KeyboardKitSwiftUI
KeyboardKitSwiftUI extends KeyboardKit with SwiftUI functionality.
It's temporarily a separate framework, since Xcode can't handle iOS 13 features in a framework that targets iOS 11.
When this is fixed or this project stops supporting iOS 11 and 12, this library will be added to KeyboardKit.
SwiftUI Support
KeyboardKitSwiftUI has helps you build KeyboardKit-based keyboard extensions in SwiftUI.
To setup a keyboard extension to use KeyboardKitSwiftUI, and set up your input view controller with setup<Content: View>(with view: Content). It takes a custom SwiftUI View and will use this view to resize the extension. This will also setup the keyboard with an ObservableKeyboardContext and a standard keyboard style.
You can then add any views you want to the keyboard view and use the rich set of extensions and utilities that this library provides.
Contextcontains an observable context and SwiftUI-specific context extensions.Extensionscontains SwiftUI-specific extensions.Gesturescontains SwiftUI-specific keyboard gestures.Settingscontains SwiftUI-specific settings extensions.Systemcontains views and extensions that helps you create system keyboard mimicking keyboards..Toastcontains SwiftUI-specific components to show a toast on top of a keyboard extension.Viewscontains SwiftUI-specific keyboard views.
You can read about some of this in the main project's readme collection.
How to create keyboards with SwiftUI
There is no magic to using this library with SwiftUI. You can use any views you like, and just let them trigger actions when they are tapped, pressed etc.
However, this repo has a bunch of views and utilities to help you simplify this. This is stil very much a work in progress, but my goal is to have great SwiftUI support in KeyboardKit 4.0. So far, the support is pretty basic.
Basically, you can create keyboards in a wide variety of ways:
- Use any views and manually call the action handler when they are tapped, pressed etc.
- Use any views and use
View+KeyboardGesturesto trigger any functions when they are tapped, pressed etc. - Use any views and use
View+KeyboardActionto apply a certain keyboard action to the view. - Use any views and use
View+Systemto apply various system look and feel to them, e.g.systemKeyboardButtonStyle. - Use
SystemKeyboardButtonto create buttons that try to mimic the native look and feel for the provided keyboard action. - Use any of the many views in the
Viewsnamespace to create more complex keyboards.
Note that the System namespace is intended to build keyboards that resemble system keyboards. They currently provide little customizations.
Demo application
There is a SwiftUI-specific demo keyboard in the main KeyboardKit repository.
To try it out, run the demo project, enabe the SwiftUI keyboard in settings and you're good to go.
Installation
Swift Package Manager
https://github.com/danielsaidi/KeyboardKitSwiftUI.git
CocoaPods
target 'MyApp' do
pod 'KeyboardKit'
end
target 'MyKeyboard' do
pod 'KeyboardKit'
end