FKKeyboardViewController

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:

  • The method createConfiguration will be called after the keyboard is created, as soon as @c -viewDidLoad is invoked. Here you should add all the different configurations for your custom keyboard.
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
    }
  }

Summary

Event Description
createConfiguration Create startup configuration.
deleteFullDocumentContext Asynchronously deletes the full text document proxy by moving the text cursor recursively.
readFullDocumentContext Asynchronously reads the full text document proxy by moving the text cursor recursively.

CreateConfiguration

override func createConfiguration() -> KeyboardConfiguration {
   let config = KeyboardConfiguration()
   return config
}

Notes:

  • This method must be overriden by subclasses to return a configuration containing, in particular, a valid LicenseConfiguration object.
  • Do not call super’s implementation. Doing that will throw an exception.
  • This method gets invoked as soon as -viewDidLoad is invoked. Initialize any dependency needed by this method in -viewDidLoad before calling super ’s implementation.
  • View KeyboardConfiguration to understand all the different configurations that may be applied.

DeleteFullDocumentContext

Asynchronously deletes the full text document proxy by moving the text cursor recursively.

  do {
    try await deleteFullDocumentContext()
  } 
  catch{
    let readError = error as? FullDocumentContext.Error
    // Error handling
    }
  }

Notes:

There are some circumstances that can make the deleteFullDocumentContext() method fail (e.g. user moves the cursor manually or it is cancelled programmatically). In these cases the deleteFullDocumentContext() throws an error of type FullDocumentContext.Error.

ReadFullDocumentContext

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:

  • The UI of the keyboard does not change and is not blocked at all. If the user manually changes the text input (e.g. selects a different text field in the app) or if they perform any keyboard interaction (e.g. pressing any keyboard key or button), then the full document read is cancelled (reporting a FullDocumentContext/Error/userCancelled error).
  • The cursor will move around the text to be able to report back to you.
  • The cursor will return to the initial position if there is no Error.
  • It is expected from you to prevent the user from using the keyboard, as keyboard interactions while reading the full text will result in an error.

The method returns a struct called FullDocumentContext.

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.


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on December 11, 2024