This repository was archived by the owner on Oct 5, 2023. It is now read-only.
File tree 1 file changed +11
-1
lines changed
react-native-android-fragment/src/main/java/com/hudl/oss/react/fragment
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 37
37
38
38
import com .facebook .infer .annotation .Assertions ;
39
39
import com .facebook .react .ReactApplication ;
40
+ import com .facebook .react .ReactInstanceManager ;
40
41
import com .facebook .react .ReactNativeHost ;
41
42
import com .facebook .react .ReactRootView ;
43
+ import com .facebook .react .common .LifecycleState ;
42
44
import com .facebook .react .devsupport .DoubleTapReloadRecognizer ;
43
45
import com .facebook .react .modules .core .DefaultHardwareBackBtnHandler ;
44
46
import com .facebook .react .modules .core .PermissionAwareActivity ;
@@ -152,7 +154,15 @@ public void onDestroy() {
152
154
mReactRootView = null ;
153
155
}
154
156
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
+ }
156
166
}
157
167
}
158
168
You can’t perform that action at this time.
0 commit comments