Custom Keyboard Extension - toggle vs collapse

Hi all. My app has a custom keyboard extension and I am trying to figure out a way to differentiate between a user manually exiting my keyboard vs the entire keyboard being collapsed or hidden. My problem is specifically on on iPhones >= X aka models that do not have a home button.

The viewWillDisappear lifecycle method is great for handling both of the above. But I need a way to separate them.

I have my own button that advances to the next input which I can account for (green circle). What I do not know how to account for is the user pressing Apple's globe icon to advance to the next input (red circle).

Does anyone know a way to react to a user pressing the globe icon/a generic way to know if the user has switched keyboards as opposed to the keyboard going away.

Replies

I use this to handle keyboard change and find out if my keyboard is selected

.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillChangeFrameNotification)) { _ in
       if let currentInputMode = UIResponder.currentInputMode {
              let language = currentInputMode.primaryLanguage
              if language == "cls" {
                    isPresented = false
              }
        }
 }
extension UIResponder {
    static var currentInputMode: UITextInputMode? {
        return UIApplication.shared.windows.first?.windowScene?.textInputMode
    }
}