KeyboardKit icon indicating copy to clipboard operation
KeyboardKit copied to clipboard

SwiftUI Modifier support

Open joehinkle11 opened this issue 5 years ago • 1 comments

I know this is out there, but it would be really neat if it were possible to accomplish this with a SwiftUI modifier

joehinkle11 avatar Jan 28 '21 01:01 joehinkle11

I think what you’re asking for is to allow keyboard control when an app uses SwiftUI as easily as KeyboardKit gives you when using UIKit. There would be two main parts needed for this:

  • Something in UIKit code (either a hosting controller subclass or something above it such as the app delegate) that sets up the UIKeyCommands. This needs two-way communication with the SwiftUI code to determine when key events are possible and to handle those events. The idea of exposing key command globally from one place is perfectly fine because that’s how the Mac menu bar works. You just need to be extra mindful of filtering commands correctly in canPerformAction.
  • Re-implementing each KeyboardKit class using SwiftUI views. I think very little of the code would be shareable, and this would only be possible at all if SwiftUI provides API to read and modify the state as we need. E.g. what the currently selected item is and can we programmatically change it. I haven’t looked too much into this but I suspect SwiftUI mostly won’t provide sufficient API. There is a lot to cover here such as List, Form, NavigationView, stacks etc.

Since it’s mostly just me working on KeyboardKit at the moment I have to pick where I spend my time. Realistically I don’t see myself reimplementing functionality in SwiftUI any time soon, but I’m very open to contributions in this area.

douglashill avatar Jan 28 '21 18:01 douglashill