EventBus

An event bus for event notifications.

The EventBus class facilitates the process of subscribing to and receiving notifications triggered by actions within the keyboardSDK.

Summary

Event Description
activityEvent A publisher for activity related events.
configurationEvent A publisher for configuration related events.

ActivityEvent

languageChanged
autocorrectionChanged
keyboardAction

LanguageChanged

Event sent when the language of the keyboard changes.

languageChanged(locale: String)

AutocorrectionChanged

Event sent when the auto correction is modified by the user via the magic button (long press on the emoji button).

autoCorrectionchanged(enabled: Bool)

KeyboardAction

Event sent when the user performs a simple action on the keyboard, for example: tap, long press, swipe.

keyboardAction(type: ActionType)

ActionType includes a different number of actions such as:

backspace Action type that corresponds to the user tapping the backspace button.
spacebar ction type that corresponds to the user tapping the spacebar button.
enter Action type that corresponds to the user tapping the enter button.
shiftOn Action type that corresponds to the user tapping the shift button to enable upper-case keyboard.
shiftOff Action type that corresponds to the user tapping the shift button to enable lower-case keyboard.
shiftCapsLock Action type that corresponds to the user tapping the shift button to enable upper-case keyboard with caps lock on.
showLetters Action type that corresponds to the user tapping the ABC button to open the letter keyboard back from the symbols keyboard.
showNumberAndSymbols Action type that corresponds to the user tapping the 123 button to open the number & symbols keyboard.
showSymbols Action type that corresponds to the user tapping the #+= button to open the symbols keyboard.
tap Action type that corresponds to the user tapping a keyboard key. It has as a parameter the tapped key.
longPressStarted Action type that corresponds to the user starting a long press on a key. It has as a parameter the key.
longPressEnded Action type that corresponds to the user ending a long press on a key. It has as a parameter the key finally selected.
showTrackpad Action type that corresponds to the user starting the cursor-movement feature of the keyboard.
hideTrackpad Action type that corresponds to the user finishing the cursor-movement feature of the keyboard.
showEmojis Action type that corresponds to the user opening the emoji panel.
hideEmojis Action type that corresponds to the user closing the emoji panel.
swipeStarted Action type that corresponds to the user starting a swipe input. It has as a paramter the first key.
swipeEnded Action type that corresponds to the user finishing a swipe input.. It has as a paramter the detected word.

ConfigurationEvent

ActivationStatusChanged

Event sent whenever the license activation status changes. Contains the new status.

activationStatusChanged(status: KeyboardActivationStatus) 

Usage

There are three important points while using the eventbus:

  1. Subscribe to the events on the viewWillAppear and unsubscribe on the viewWillDisappear
  2. It depends on the Combine framework. You need to import it.
  3. The events are triggered from a background thread. Any change on the UI must be enqueued on the main thread.

Example:


    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        subscribeToEvents()
    }
    
    // UnSubscribe to the events that we want
    //
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        observations.removeAll()
    }
    
    private var observations: Set<AnyCancellable> = []
    
    private func subscribeToEvents(){
        eventBus.activity.sink { activityEvent in
            print("Activity event: \(activityEvent)")
            
            // Important! All eventBus events come from a background thread, if you want to make UI changes, use the main thread.
            //
        }
        .store(in: &observations)
        
        eventBus.configuration.sink { configurationEvent in
            print("Configuration event: \(configurationEvent)")
        }.store(in: &observations)
    }

Sample Code:

Check directly the sample code on how to use the eventbus.


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 November 29, 2023