mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Call onDropViewInstance on all Views when stopSurface is called
Summary: Call `onDropViewInstance` on all Views when stopSurface is called. We used to do this but stopped doing it ~6 months ago. This did not cause any prod issues but is not correct. This allows product code to do cleanup upon view deletion. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D28388929 fbshipit-source-id: a8f06d4b1b12a11a907667e0a837c653db035941
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4d87d8c6b2
commit
3c7809ed0d
+21
-11
@@ -257,6 +257,11 @@ public class SurfaceMountingManager {
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// We must call `onDropViewInstance` on all remaining Views
|
||||
for (ViewState viewState : mTagToViewState.values()) {
|
||||
onViewStateDeleted(viewState);
|
||||
}
|
||||
|
||||
// Evict all views from cache and memory
|
||||
mLastSuccessfulQueryTime = System.currentTimeMillis();
|
||||
mTagSetForStoppedSurface = mTagToViewState.keySet();
|
||||
@@ -794,6 +799,21 @@ public class SurfaceMountingManager {
|
||||
mJSResponderHandler.setJSResponder(initialReactTag, view.getParent());
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void onViewStateDeleted(ViewState viewState) {
|
||||
// Destroy state immediately instead of waiting for Java GC.
|
||||
if (viewState.mStateWrapper != null) {
|
||||
viewState.mStateWrapper.destroyState();
|
||||
viewState.mStateWrapper = null;
|
||||
}
|
||||
|
||||
// For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
|
||||
ViewManager viewManager = viewState.mViewManager;
|
||||
if (!viewState.mIsRoot && viewManager != null) {
|
||||
viewManager.onDropViewInstance(viewState.mView);
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void deleteView(int reactTag) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
@@ -816,17 +836,7 @@ public class SurfaceMountingManager {
|
||||
// or StopSurface being called, so we do not handle deleting descendents of the View.
|
||||
mTagToViewState.remove(reactTag);
|
||||
|
||||
// Destroy state immediately instead of waiting for Java GC.
|
||||
if (viewState.mStateWrapper != null) {
|
||||
viewState.mStateWrapper.destroyState();
|
||||
viewState.mStateWrapper = null;
|
||||
}
|
||||
|
||||
// For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
|
||||
ViewManager viewManager = viewState.mViewManager;
|
||||
if (!viewState.mIsRoot && viewManager != null) {
|
||||
viewManager.onDropViewInstance(viewState.mView);
|
||||
}
|
||||
onViewStateDeleted(viewState);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
||||
Reference in New Issue
Block a user