software-mansion / software-mansion/react-native-screens
[Android] Crash when launching 2 ReactFragment in an activity
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.7k
- Forks
- 713
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 71
Description
Description
My app has an activity + several fragments design for Android phone, and integrate react native into fragment. When launching 2 ReactFragment one on top of the other, the app will be crash. Below is the stack trace:
JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.lang.IllegalArgumentException: [RNScreens] Attempt to use context detached from activity
java_vm_ext.cc:599] at android.app.Activity com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.requireActivity() (ScreenDummyLayoutHelper.kt:223)
java_vm_ext.cc:599] at float com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.computeDummyLayout(int, boolean) (ScreenDummyLayoutHelper.kt:181)
java_vm_ext.cc:599] at void com.facebook.jni.NativeRunnable.run() (NativeRunnable.java:-2)
java_vm_ext.cc:599] at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:959)
java_vm_ext.cc:599] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:100)
java_vm_ext.cc:599] at void com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(android.os.Message) (MessageQueueThreadHandler.kt:20)
java_vm_ext.cc:599] at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:232)
java_vm_ext.cc:599] at void android.os.Looper.loop() (Looper.java:317)
java_vm_ext.cc:599] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(com.facebook.react.common.futures.SimpleSettableFuture) (MessageQueueThreadImpl.kt:175)
java_vm_ext.cc:599] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.$r8$lambda$ldnZnqelhYFctGaUKkOKYj5rxo4(com.facebook.react.common.futures.SimpleSettableFuture) (MessageQueueThreadImpl.kt:-1)
java_vm_ext.cc:599] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion$$ExternalSyntheticLambda0.run() (D8$$SyntheticClass:0)
java_vm_ext.cc:599] at void java.lang.Thread.run() (Thread.java:1012)
java_vm_ext.cc:599]
java_vm_ext.cc:599] in call to NewStringUTF
java_vm_ext.cc:599] from void com.facebook.jni.NativeRunnable.run()
runtime.cc:708] Runtime aborting...
runtime.cc:708] Dumping all threads without mutator lock held
If a native fragment on top of ReactFragment, it'll be fine.
Steps to reproduce
- Launching 2 ReactFragment one on top of the other, let's say fragment1 at bottom and fragment2 at top.
- Navigate back from fragment2.
- Click anything on fragment1 to navigate to elsewhere.
- Crash will occur.
Snack or a link to a repository
https://github.com/chenxiangcxc/RNFragmentActivityRefDemo
Screens version
4.10.0
React Native version
0.79.0
Platforms
Android
JavaScript runtime
None
Workflow
None
Architecture
None
Build type
None
Device
None
Device model
No response
Acknowledgements
Yes
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction repository and inspect ScreenDummyLayoutHelper.kt, especially requireActivity() and computeDummyLayout(), using the supplied stack trace as the entry point. Reproduce the sequence of navigating back from the second ReactFragment and then interacting with the first; done means that flow no longer crashes when the fragment context is detached.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100