This is the core class for the creation of your own custom keyboard.
KeyboardConfiguration instance will be called from KeyboardViewController.
The input method class that can be extended to configure the keyboard behaviour, respond to keyboard requests, and listen to keyboard events.
Notes:
class KeyboardViewController: FleksyKeyboardSDK.FKKeyboardViewController {
/// - Important: Every time the keyboard appears it calls in this order: ``viewDidLoad`` -> ``viewWillAppear`` -> ``viewDidAppear``.
/// Keyboard extensions don't reuse the view, which means that in every appearance we recreate what's inside ``viewDidLoad``.
/// This behaviour is different from the normal iOS ViewController.
override func viewDidLoad() {
super.viewDidLoad()
}
override func createConfiguration() -> KeyboardConfiguration {
// Add all your custom configuration here.
// Add your license key and secret here.
let config = KeyboardConfiguration()
return config
}
}
Event | Description |
---|---|
createConfiguration | Create startup configuration. |
readFullDocumentContext | Asynchronously reads the full text document proxy by moving the text cursor recursively. |
override func createConfiguration() -> KeyboardConfiguration {
let config = KeyboardConfiguration()
return config
}
Notes:
-viewDidLoad
is invoked. Initialize any dependency needed by this method in -viewDidLoad
before calling super ’s implementation.Asynchronously reads the full text document proxy by moving the text cursor recursively.
do {
let fullContext = try await readFullDocumentContext()
}
catch{
let readError = error as? FullDocumentContext.Error
// Error handling
}
}
Notes:
FullDocumentContext/Error/userCancelled
error).The method returns a struct
called FullDocumentContext.
public struct FullDocumentContext {
/// Full textual context before the insertion point in the current text input object.
public var fullDocumentContextBeforeInput: String
/// Full textual context after the insertion point in the current text input object.
public var fullDocumentContextAfterInput: String
}
The struct has two main parameters: text before the cursor and text after the cursor. It returns the text previous to the cursor and after the cursor in case that there is no error.
There are some circumstances that can make the readFullDocumentContext()
method fail (e.g. user moves the cursor manually or it is cancelled programmatically). In these cases the readFullDocumentContext()
throws an error of type FullDocumentContext.Error
.