This repository was archived by the owner on Oct 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
react-native-android-fragment/src/main/java/com/hudl/oss/react/fragment Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 3737
3838import com .facebook .infer .annotation .Assertions ;
3939import com .facebook .react .ReactApplication ;
40+ import com .facebook .react .ReactInstanceManager ;
4041import com .facebook .react .ReactNativeHost ;
4142import com .facebook .react .ReactRootView ;
43+ import com .facebook .react .common .LifecycleState ;
4244import com .facebook .react .devsupport .DoubleTapReloadRecognizer ;
4345import com .facebook .react .modules .core .DefaultHardwareBackBtnHandler ;
4446import com .facebook .react .modules .core .PermissionAwareActivity ;
@@ -152,7 +154,15 @@ public void onDestroy() {
152154 mReactRootView = null ;
153155 }
154156 if (getReactNativeHost ().hasInstance ()) {
155- getReactNativeHost ().getReactInstanceManager ().onHostDestroy (getActivity ());
157+ ReactInstanceManager reactInstanceMgr = getReactNativeHost ().getReactInstanceManager ();
158+ reactInstanceMgr .onHostDestroy (getActivity ());
159+
160+ // onDestroy may be called on a ReactFragment after another ReactFragment has been
161+ // created and resumed with the same React Instance Manager. Make sure we only clean up
162+ // host's React Instance Manager if no other React Fragment is actively using it.
163+ if (reactInstanceMgr .getLifecycleState () != LifecycleState .RESUMED ) {
164+ getReactNativeHost ().clear ();
165+ }
156166 }
157167 }
158168
You can’t perform that action at this time.
0 commit comments