Skip to content

iOS: crash «Collection was mutated while being enumerated» in TrueSheetKeyboardObserver keyboardWillChangeFrame: when a footer mounts while the keyboard shows #1025

Open

Description

@Kijomimi

Before submitting a new issue

  • I tested using the latest version of the library.
  • I tested using a supported version of React Native.
  • I checked for existing issues that might answer my question.

Bug Summary

On iOS the app crashes with NSGenericException («Collection was mutated while being enumerated») inside -[TrueSheetKeyboardObserver keyboardWillChangeFrame:].

It happens when a presented sheet mounts a new footer (a footer with a TextInput) and that input is focused right away: the keyboard starts to show and the observer walks _delegates with fast enumeration. The backtrace does not show the mutating call; my reading of the source is that the newly mounted TrueSheetFooterView registers itself during that walk (TrueSheetContainerView sets _footerView.keyboardObserver → setKeyboardObserver: → addDelegate:), which mutates the hash table being enumerated.

Expected: the sheet lifts with the keyboard. Actual: SIGABRT, the app closes.

Affected Platforms

  • iOS
  • Android
  • Web
  • Other

Library Version

4.1.0 (the loop is the same on main today: ios/core/TrueSheetKeyboardObserver.mm, for (id<TrueSheetKeyboardObserverDelegate> delegate in _delegates))

Environment Info

react-native: 0.88.1 (New Architecture)
react: 19.3.x
@lodev09/react-native-true-sheet: 4.1.0
Xcode: 27.2 (27B52)
Reproduced on: iPhone 15 simulator, iOS 26.5, software keyboard on
Also seen on: a physical iPhone, iOS 27.2 (the app closed on the same action; no crash report was written for that one)

Steps to Reproduce

  1. Present a sheet with detents={['auto']} and no footer, content: a short list.
  2. On a tap inside the sheet, switch the sheet to an inner step in the same presentation: render a footer with a TextInput (a search field) and a long list as the content.
  3. Focus that TextInput right after the step renders (useEffect → ref.focus()), so the keyboard starts to show while the new footer is mounting.
  4. With the software keyboard on, the app crashes. In our app it does not crash when the focus comes later (a tap on the input after the footer has mounted), nor when the footer was mounted together with the sheet and focused as it presents.

A sketch of the sequence (this is what our app did through a thin wrapper; I have not verified this exact snippet in an isolated project):

const [step, setStep] = useState(false);
const inputRef = useRef<TextInput>(null);

useEffect(() => {
  if (step) inputRef.current?.focus();
}, [step]);

<TrueSheet
  ref={sheet}
  detents={['auto']}
  footer={step ? <TextInput ref={inputRef} placeholder="Search" /> : undefined}
>
  {step ? <LongList /> : <Button title="Show more" onPress={() => setStep(true)} />}
</TrueSheet>

Repro

No public repro yet, sorry: it was found in a private app. The native stack below points at the exact loop.

Additional Context

Last exception backtrace (simulator, iOS 26.5; app frames replaced with <app>):

CoreFoundation   __exceptionPreprocess
libobjc.A.dylib  objc_exception_throw
CoreFoundation   +[__NSFastEnumerationEnumerator allocWithZone:]
Foundation       -[NSConcreteHashTable countByEnumeratingWithState:objects:count:]
<app>            -[TrueSheetKeyboardObserver keyboardWillChangeFrame:]
CoreFoundation   __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
...
Foundation       -[NSNotificationCenter postNotificationName:object:userInfo:]
TextInputUI      -[TUIKeyboardTrackingCoordinator postNotificationWithName:userInfo:]
...
UIKitCore        -[UIKeyboardSceneDelegate setInputViews:]
UIKitCore        __102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.568
UIKitCore        __65-[UIPeripheralHost(UIKitInternal) queueDelayedTask:forKey:delay:]_block_invoke
libdispatch.dylib _dispatch_main_queue_drain

Triggered thread: __NSFastEnumerationMutationHandler → objc_exception_throw → abort (EXC_CRASH, SIGABRT).

A possible fix is to enumerate a snapshot, so a delegate added or removed during the callbacks can't break the loop:

for (id<TrueSheetKeyboardObserverDelegate> delegate in _delegates.allObjects) {

(NSHashTable.allObjects returns an NSArray copy of the live delegates; it holds them only for the loop, and a delegate added during the callbacks gets the next notification.)

Our workaround for now: don't focus a footer input in the same moment the footer mounts in an already presented sheet; let the user tap it.

Activity

  1. github-actions commented on Nov 14, 2026

    @github-actions

    Hey @Kijomimi! Thanks for opening the issue.

    It looks like your issue is missing a valid reproduction link.

    A minimal reproduction helps us investigate and fix the issue faster. Without one, we may not be able to help.

    Please provide one of the following:

    • A GitHub repository under your username
    • An Expo Snack

    See "How to create a Minimal, Reproducible Example" for more guidance.

    You can edit your original issue or leave a comment with the repro link. Issues without reproductions may be closed after 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproNeed to replicate this issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions