-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle React Native loaded on Fragment #1553
Conversation
Also add some comments that describe the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment below
// We are in some custom setup & we want to use the closest fragment manager in hierarchy. | ||
// `findFragment` method throws IllegalStateException when it fails to resolve appropriate | ||
// fragment. It might happen when e.g. React Native is loaded directly in Activity | ||
// but some custom fragments are still used. However such use case seems highly unlikely | ||
// so, as for now, we let application crash. | ||
FragmentManager.findFragment<Fragment>(rootView).childFragmentManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially we could catch the exception here and fallback to context.supportFragmentManager
:
// We are in some custom setup & we want to use the closest fragment manager in hierarchy. | |
// `findFragment` method throws IllegalStateException when it fails to resolve appropriate | |
// fragment. It might happen when e.g. React Native is loaded directly in Activity | |
// but some custom fragments are still used. However such use case seems highly unlikely | |
// so, as for now, we let application crash. | |
FragmentManager.findFragment<Fragment>(rootView).childFragmentManager | |
// We are in some custom setup & we want to use the closest fragment manager in hierarchy. | |
// `findFragment` method throws IllegalStateException when it fails to resolve appropriate | |
// fragment. It might happen when e.g. React Native is loaded directly in Activity | |
// but some custom fragments are still used. However such use case seems highly unlikely | |
// so, as for now, we let application crash. | |
try { | |
FragmentManager.findFragment<Fragment>(rootView).childFragmentManager | |
} catch (IllegalStateException e) { | |
context.supportFragmentManager | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change added with 714ddea
There are still issues after making the changes |
Description
Fixes #1506
ScreenContainer#setupFragmentManager
method resolvesFragmentManager
instance forScreenContainer
to use for conducting transactions. Until now, when first (not nested)ScreenContainer
was initialised we tookFragmentManager
from top level activity, but it leads to conflicts with native Android navigation when React Native is not loaded directly in main activity (there are cases (see #1506) when bothreact-native-screens
& Android native navigation use simultaneously the same FragmentManager leading to crashes).Changes
Added a method resolving fragment manager whose fragment's view is
ReactRootView
.Test code and steps to reproduce
See #1506 for crash description and how to reproduce.
Checklist