react-native-screens: Crash on Android with react-navigation stack

When I navigate to this specific screen the app is crashing. It works fine on iOS and it works fine if I comment out enableScreens() and not use react-native-screens

It’s a pretty standard screen, apollo hooks + SectionList and some Text View TouchableOpacity (from react-native-gesture-handler)

Here is the log collected by Sentry, is there anything I can do to debug and help finding the root cause?

java.lang.IllegalStateException: Fragment already added: ScreenFragment{e9e00a9 (89d81b03-c200-4966-881c-38bb9e88da42) id=0x175}
    at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1379)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:399)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1830)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
    at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 18
  • Comments: 29 (9 by maintainers)

Most upvoted comments

Same issue with react-navigation v5 and react-native-screens v2.0.0-beta.2 Happens when going back to previous screen

Quick workaround for production if necessary: what helped us was actually removing useScreens method while using android platform for now.

import {useScreens} from 'react-native-screens';
// TODO: Remove condition after react-navigation this issue is fixed
if (Platform.OS === 'ios') {
  useScreens();
}

I’m seeing a similar error in the crash reports on google console for apps in production, maybe I should disable enableScreens() on android. Here are my library versions:

"@react-navigation/native": "^5.6.1",
"@react-navigation/stack": "^5.6.2",
"react-native-screens": "^2.9.0",

I’m using the @react-navigation/stack navigator, not the native stack navigator. I haven’t seen this error while testing, but it’s fairly common in my crash logs in production.

Sorry for the late reply, I was debugging the code and found out the issue was not with navigation but rather the image component, so had to replace that with a different library.

@kmagiera

2020-02-18 16:11:51.104 14862-14862/xxx E/AndroidRuntime: FATAL EXCEPTION: main
    Process: xxx, PID: 14862
    java.lang.ClassCastException: com.bumptech.glide.manager.SupportRequestManagerFragment cannot be cast to com.swmansion.rnscreens.ScreenFragment
        at com.swmansion.rnscreens.ScreenContainer.onUpdate(ScreenContainer.java:255)
        at com.swmansion.rnscreens.ScreenContainer.updateIfNeeded(ScreenContainer.java:238)
        at com.swmansion.rnscreens.ScreenContainer.access$000(ScreenContainer.java:23)
        at com.swmansion.rnscreens.ScreenContainer$1.doFrame(ScreenContainer.java:38)
        at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:174)
        at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:965)
        at android.view.Choreographer.doCallbacks(Choreographer.java:791)
        at android.view.Choreographer.doFrame(Choreographer.java:722)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

could this be related to fix?

BTW. ToggleInspector works now as well! thanks for fix 😃

I hear from @adamczyk777 that this crash no longer occurs on the most recent release (2.0.0-beta.6). As I don’t see any repro case here I could use to verify I can only ask whoever reported the crash here if you still get it on beta.6. In case you do please comment below or start a new issue with a repro scenario.

I’ve tried to start a new project from scratch, added react-navigation and all the dependencies, added stack and tabs, created a similar navigation setup but it doesn’t crash so I’ll need to slowly add more things until it breaks to pin down what’s causing this.