Skip to content

Infinite recursion in respondsToSelector with custom UITextField forwarding delegate #1513

Description

@iOSMahmoudSaad

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

  1. Launch the application.
  2. Tap the custom text field.
  3. 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

Metadata

Metadata

Assignees

Labels

repro providedIssue contains reproduction repository/code🍎 iOSiOS specific🎯 crashLibrary triggers a crash of the app

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions