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:
Joshua Gross
2021-05-12 14:05:56 -07:00
committed by Facebook GitHub Bot
parent 4d87d8c6b2
commit 3c7809ed0d
@@ -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