mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Call invalidate on ViewManager on context destroy (#37481)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37481 ViewManagers inherit from BaseJavaModule so we should honour the same lifecycle for them as we do for native modules, which is to call `invalidate` / `onCatalystInstanceDestroy` when the ReactContext is destroyed. This allows the ViewManager to do any cleanup which cannot happen at the View level. Changelog: [Android][Fixed] ViewManagers now receive an invalidate callback Reviewed By: cortinico Differential Revision: D45945678 fbshipit-source-id: 27c26d951b50a734c42eb033a46e599ef939e29f
This commit is contained in:
+1
@@ -429,6 +429,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
mEventDispatcher.unregisterEventEmitter(FABRIC);
|
||||
|
||||
mReactApplicationContext.unregisterComponentCallbacks(mViewManagerRegistry);
|
||||
mViewManagerRegistry.invalidate();
|
||||
|
||||
// Remove lifecycle listeners (onHostResume, onHostPause) since the FabricUIManager is going
|
||||
// away. Then stop the mDispatchUIFrameCallback false will cause the choreographer
|
||||
|
||||
+1
@@ -792,6 +792,7 @@ public class UIImplementation {
|
||||
|
||||
public void onCatalystInstanceDestroyed() {
|
||||
mViewOperationsEnabled = false;
|
||||
mViewManagers.invalidate();
|
||||
}
|
||||
|
||||
public void setViewHierarchyUpdateDebugListener(
|
||||
|
||||
+22
-6
@@ -103,12 +103,28 @@ public final class ViewManagerRegistry implements ComponentCallbacks2 {
|
||||
viewManagers = new ArrayList<>(mViewManagers.values());
|
||||
}
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (ViewManager viewManager : viewManagers) {
|
||||
viewManager.onSurfaceStopped(surfaceId);
|
||||
}
|
||||
() -> {
|
||||
for (ViewManager viewManager : viewManagers) {
|
||||
viewManager.onSurfaceStopped(surfaceId);
|
||||
}
|
||||
};
|
||||
if (UiThreadUtil.isOnUiThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
UiThreadUtil.runOnUiThread(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
/** Called on instance destroy */
|
||||
public void invalidate() {
|
||||
final List<ViewManager> viewManagers;
|
||||
synchronized (this) {
|
||||
viewManagers = new ArrayList<>(mViewManagers.values());
|
||||
}
|
||||
Runnable runnable =
|
||||
() -> {
|
||||
for (ViewManager viewManager : viewManagers) {
|
||||
viewManager.invalidate();
|
||||
}
|
||||
};
|
||||
if (UiThreadUtil.isOnUiThread()) {
|
||||
|
||||
Reference in New Issue
Block a user