react-native-screens: IOS Modal causing glitches and crashs when using exiting animation inside it

Description

description is not missing *test

related to

INFO: copied from my issue on expo-router repo as its still the same

  • read the crash report below and you’ll see it’s related to react-native-screens
  • only happens on iOS
  • you really need to use a custom header doesn’t matter what kind of when it’s there it’ll crash if screen contains a view with exiting animation
  • seems to be new arch related did not happen before so I had to temporary remove all exiting animations and or modals in my project to continue trying out the new arch

Expected Behavior

I can dismiss the modal containing any basic headers configured in screenOptions and I should be able to use functionalities which are not marked as unstable or experimental like exiting animations on reanimated.

Whats actually happening

App and Modal screen glitches completely out after swiping it down a few times.

  • Note: You don’t even have to do it as fast as I did on the provided video.

I am also sure that this bug is different from https://github.com/expo/expo/issues/32874#issuecomment-2477988050 as react-native-screens does not fix that issue and the cause is precise problem.

  • Did not happen on previous SDK eg old arch and react-native-screens < 4
  • I think that issue is related to reanimated and expo-router eg. react-navigation react-native-screens.
  • What’s weird is that the cause is so specific ONLY IF you use a custom header and happen to have an exiting animation on any component in that modal it glitches out so it might be connected.
updated video

https://github.com/user-attachments/assets/d8842d5b-1e1a-4e81-b465-d359794ee3dc

Bildschirmfoto 2024-12-11 um 12 51 37

crash report

[Foundation] *** Assertion failure in -[RNSScreenStackView setModalViewControllers:](),
/Users/yasinsimsek/Projects/ExpoSDK52-Modal-issue/node_modules/react-native-screens/ios/RNSScreenStack.mm:452
[CoreFoundation] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modally presented controllers are
being reshuffled, this is not allowed'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001804b757c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x000000018008eda8 objc_exception_throw + 72
2   Foundation                          0x0000000180e7a398 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
3   ExpoSDK52Modalissue.debug.dylib     0x0000000108e33d8c -[RNSScreenStackView setModalViewControllers:] + 1712
4   ExpoSDK52Modalissue.debug.dylib     0x0000000108e35de0 -[RNSScreenStackView updateContainer] + 1208
5   ExpoSDK52Modalissue.debug.dylib     0x0000000108e34588 __46-[RNSScreenStackView setModalViewControllers:]_block_invoke + 220
6   ExpoSDK52Modalissue.debug.dylib     0x0000000108e34e14 __46-[RNSScreenStackView setModalViewControllers:]_block_invoke_2 + 144
7   UIKit                               0x0<…>

Steps to reproduce

  1. create a modal screen on ios
  2. put an AnimatedView with exiting animation inside the modal AND use a CUSTOM header (very important)
  3. open and close the modal using swipe / touch gestures and it’ll crash on you eventually

Snack or a link to a repository

https://github.com/YasinAkimura/expo-sdk-52-modal-bug-reanimated

Screens version

4.3.0

React Native version

0.76.3

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo bare workflow

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

iOS simulator

Device model

iPhone 16 Pro (iOS 18.1)

Acknowledgements

Yes

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I forwarded the issue to reanimated team

I’m also affected by this regression.

I’m going to try using this as a workaround, taking advantage of the fact that using the native header for the modal route prevents the crash. This adds the header on iOS, but makes it fully transparent. Tap targets underneath the header won’t work, but for my use case it’s very unlikely that the user will scroll such that a tap target would be under the transparent header and even if they do that’s vastly preferable to the crash.

        <Stack.Screen
          name="MyModal"
          options={{
            presentation: 'modal',
            ...(Platform.OS === 'ios'
              ? {
                  headerShown: true,
                  headerTransparent: true,
                  headerTitle: '',
                }
              : {
                  headerShown: false,
                }),
          }}
          component={MyModalComponent}
        />

I forwarded the issue to reanimated team

Is there a reference, or a new issue or will updates be posted here? Thx for looking into this 🙏

Hi @YasinAkimura! I prepared a fix in the reanimated repo. Can you check it out?

I can confirm that the issue happens when

  • NOT having headerShown true
  • having exiting animations on some components
  • presentantion is modal or bottomSheet

I have “react-native-screens”: “4.10.0”, “react-native-reanimated”: “3.17.5”, “react-native”: “0.76.9”(tested on 0.79 also)

Have anyone tried to find some versions that work ok?

I am trying to migrate from “@react-navigation/stack” (which works fine) to “@react-navigation/native-stack”

Thanks for the update!