mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 17:30:38 +08:00
Force react applications to be explicitly unmounted
Summary: We previously were unmounting the react application unconditionally when the ReactRootView#onDetachedFromWindow. This is nice in that it automatically allows us to reclaim memory, but there are many scenarios where a ReactRootView can be embedded in another piece of UI that detaches its children as part of its normal function (e.g. ListView, RecyclerView, ViewPager, etc). As such, we will now enforce that the hosting Activity/Fragment/??? explicitly calls unmountReactApplication in the same way it calls startReactApplication. For Applications extending ReactActivity/AbstractReactActivity, this will happen automatically in onDestroy. Reviewed By: foghina Differential Revision: D3265161 fb-gh-sync-id: 4d49b0c41256213f00874f57e784aa8741dbf394 fbshipit-source-id: 4d49b0c41256213f00874f57e784aa8741dbf394
This commit is contained in:
committed by
Facebook Github Bot 7
parent
f7ce0c1c2f
commit
54f7ae1c02
@@ -27,6 +27,7 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
|
||||
"Overlay permissions needs to be granted in order for react native apps to run in dev mode";
|
||||
|
||||
private @Nullable ReactInstanceManager mReactInstanceManager;
|
||||
private @Nullable ReactRootView mReactRootView;
|
||||
private LifecycleState mLifecycleState = LifecycleState.BEFORE_RESUME;
|
||||
private boolean mDoRefresh = false;
|
||||
|
||||
@@ -138,7 +139,7 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
|
||||
}
|
||||
|
||||
mReactInstanceManager = createReactInstanceManager();
|
||||
ReactRootView mReactRootView = createRootView();
|
||||
mReactRootView = createRootView();
|
||||
mReactRootView.startReactApplication(mReactInstanceManager, getMainComponentName(), getLaunchOptions());
|
||||
setContentView(mReactRootView);
|
||||
}
|
||||
@@ -169,6 +170,9 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
mReactRootView.unmountReactApplication();
|
||||
mReactRootView = null;
|
||||
|
||||
if (mReactInstanceManager != null) {
|
||||
mReactInstanceManager.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user