question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScreenStack throws fragment exception from pushing screen

See original GitHub issue

Description

Pushing screen in ScreenStack example gets Android fragment exception. This issue did not happen to react-native-screens@3.6.0

Stacktrace as following:

    unknown:ReactNative  E  Exception in native call
                         E  java.lang.IllegalStateException: This transaction is already being added to the back stack
                         E      at androidx.fragment.app.FragmentTransaction.disallowAddToBackStack(FragmentTransaction.java:679)
                         E      at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:302)
                         E      at com.swmansion.rnscreens.ScreenStack.setupBackHandlerIfNeeded(ScreenStack.kt:340)
                         E      at com.swmansion.rnscreens.ScreenStack.access$setupBackHandlerIfNeeded(ScreenStack.kt:17)
                         E      at com.swmansion.rnscreens.ScreenStack$mLifecycleCallbacks$1.onFragmentResumed(ScreenStack.kt:34)
                         E      at androidx.fragment.app.FragmentLifecycleCallbacksDispatcher.dispatchOnFragmentResumed(FragmentLifecycleCallbacksDispatcher.java:207)
                         E      at androidx.fragment.app.FragmentStateManager.resume(FragmentStateManager.java:374)
                         E      at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)
                         E      at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
                         E      at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
                         E      at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
                         E      at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2007)
                         E      at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
                         E      at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
                         E      at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
                         E      at com.swmansion.rnscreens.ScreenStack.onUpdate(ScreenStack.kt:280)
                         E      at com.swmansion.rnscreens.ScreenContainer.performUpdates(ScreenContainer.kt:294)
                         E      at com.swmansion.rnscreens.ScreensShadowNode.onBeforeLayout$lambda-0(ScreensShadowNode.kt:15)
                         E      at com.swmansion.rnscreens.ScreensShadowNode.lambda$OP8O-3NTREBtSmNbm5uT9SWXiEQ(Unknown Source:0)
                         E      at com.swmansion.rnscreens.-$$Lambda$ScreensShadowNode$OP8O-3NTREBtSmNbm5uT9SWXiEQ.execute(Unknown Source:2)
                         E      at com.facebook.react.uimanager.UIViewOperationQueue$UIBlockOperation.execute(UIViewOperationQueue.java:573)
                         E      at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:908)
                         E      at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1019)
                         E      at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:47)
                         E      at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1079)
                         E      at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
                         E      at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
                         E      at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
                         E      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1000)
                         E      at android.view.Choreographer.doCallbacks(Choreographer.java:823)
                         E      at android.view.Choreographer.doFrame(Choreographer.java:754)
                         E      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:987)
                         E      at android.os.Handler.handleCallback(Handler.java:938)
                         E      at android.os.Handler.dispatchMessage(Handler.java:99)
                         E      at android.os.Looper.loopOnce(Looper.java:201)
                         E      at android.os.Looper.loop(Looper.java:288)
                         E      at android.app.ActivityThread.main(ActivityThread.java:7858)
                         E      at java.lang.reflect.Method.invoke(Native Method)
                         E      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                         E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:984)

Screenshots

Steps To Reproduce

$ npx react-native init RN064 --version 0.64
$ cd RN064
$ yarn add 'react-native-screens@3.7.2'
$ wget https://raw.githubusercontent.com/software-mansion/react-native-screens/2.18.1/Example/nativeStack.js -O App.js
$ yarn android
# After app loaded, click the "PUSH" button and Android will throw the exception.

Expected behavior

Should able to show next screen

Actual behavior

Getting exception

Package versions

  • React: 17.0.1
  • React Native: 0.64.2
  • React Native Screens: 3.7.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Kudocommented, Sep 22, 2021

thanks, @WoLewicki! the fix in your pr works for me. just to double confirm that android hardware back key support in ScreenStack will be deprecated and be a breaking change, right?

0reactions
Kudocommented, Sep 23, 2021

@WoLewicki understand! thanks for your fix. 👏

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Android] Crash on killed app restore #114 - GitHub
Screen $ScreenFragment: calling Fragment constructor caused an exception at android.support.v4.app.Fragment.instantiate(Fragment.java:465) at ...
Read more >
Fragment code not being run when fragment is displayed on ...
The problem is none of the fragments, 1 of which is as it was when it was automatically generated using the android studio...
Read more >
Screen - Android Developers
The screen is in the process of being pushed to the screen stack, it is valid, but contents from it are not yet...
Read more >
Authentication flows - React Navigation
This is the behavior that we want from the authentication flow: when users sign in, we want to throw away the state of...
Read more >
Source Code for Screen.java - AndroidX Tech
Screen instances can also be pushed and popped to and from * a Screen stack, which ensures they adhere to the template flow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found