Prevent "Focus Movement"

I use GCKeyboard to detect key events, but if there is a text field on screen then arrow keys will cause the text field to become first responder due to the new _UIFocusEngineRepeatingPressGestureRecognizer automatically added to the window in iOS 16. Other than removing those manually, is there a way to prevent this behaviour?

Replies

A couple of ideas you could try:

  • first of if it's just a single text field you care about you can subclass and override canBecomeFocused and return NO from there.
  • if your failure case is more dynamic and not about text fields but focus in general, you can create a gesture that listens for presses and add a dynamic failure requirement for other press gestures.
  • there might be other and better options depending on what you are doing with the GCKeyboard events. If you are doing anything remotely resembling the work of focus, it would be better to migrate your code to use the focus system as that gives you a better platform specific user experience.

It's also worth pointing out that the focus gesture recognizers are available since at least iOS 15 and in some cases even earlier, so if this only becomes an issue now, something probably changed in your code as well.