Crash when using custom UITextField delegate forwarding with KeyboardController (Infinite recursion)
Environment
- React Native: 0.75.4
- react-native-keyboard-controller: 1.21.12
- react-native-reanimated: 3.17.0
- iOS
- Hermes enabled
Description
I found a crash that occurs when using react-native-keyboard-controller together with a custom UITextField subclass that forwards delegate calls using Objective-C message forwarding.
The custom text field has been used in production for a long time without issues. The crash only happens when react-native-keyboard-controller is enabled.
I created a minimal reproduction project to isolate the issue.
Reproduction
The repro project contains:
- A custom
BKForwardingTextField
- A simple React Native wrapper using
requireNativeComponent
KeyboardProvider from react-native-keyboard-controller
Steps to reproduce
- Launch the application.
- Tap the custom text field.
- The application crashes.
Expected behavior
The text field should become first responder and display the keyboard normally.
Actual behavior
The application crashes with EXC_BAD_ACCESS.
Findings
The stack trace indicates infinite recursion between:
BKForwardingTextField respondsToSelector:
KCTextInputCompositeDelegate.responds
The recursion starts when extendedTextInputTraits is queried.
Relevant stack trace:
Thread 1: EXC_BAD_ACCESS
UIKitCore`-[UITextField respondsToSelector:]
BKForwardingTextField respondsToSelector:
KCTextInputCompositeDelegate.responds
BKForwardingTextField respondsToSelector:
KCTextInputCompositeDelegate.responds
BKForwardingTextField respondsToSelector:
KCTextInputCompositeDelegate.responds
...
More specifically:
BKForwardingTextField.m:60
BKForwardingTextField.m:63
KCTextInputCompositeDelegate.swift:215
The same pattern repeats until the application crashes.
Additional Notes
The issue disappears immediately if:
react-native-keyboard-controller is removed, or
- A standard
UITextField is used instead of the forwarding text field.
This looks very similar to the recursion-related issues discussed previously:
Reproduction Project
https://drive.google.com/file/d/1eMyeBn2GwxGSqiBojo9qn-Y3DTozxjNO/view
Crash when using custom UITextField delegate forwarding with KeyboardController (Infinite recursion)
Environment
Description
I found a crash that occurs when using
react-native-keyboard-controllertogether with a customUITextFieldsubclass that forwards delegate calls using Objective-C message forwarding.The custom text field has been used in production for a long time without issues. The crash only happens when
react-native-keyboard-controlleris enabled.I created a minimal reproduction project to isolate the issue.
Reproduction
The repro project contains:
BKForwardingTextFieldrequireNativeComponentKeyboardProviderfromreact-native-keyboard-controllerSteps to reproduce
Expected behavior
The text field should become first responder and display the keyboard normally.
Actual behavior
The application crashes with
EXC_BAD_ACCESS.Findings
The stack trace indicates infinite recursion between:
BKForwardingTextField respondsToSelector:KCTextInputCompositeDelegate.respondsThe recursion starts when
extendedTextInputTraitsis queried.Relevant stack trace:
More specifically:
The same pattern repeats until the application crashes.
Additional Notes
The issue disappears immediately if:
react-native-keyboard-controlleris removed, orUITextFieldis used instead of the forwarding text field.This looks very similar to the recursion-related issues discussed previously:
Reproduction Project
https://drive.google.com/file/d/1eMyeBn2GwxGSqiBojo9qn-Y3DTozxjNO/view