From 3281714312ed524e8c3fc33f93f94288368cb35e Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 5 Nov 2019 12:30:46 -0800 Subject: [PATCH] Ensure that ReactInstanceManager is still alive when animation system updates views in Fabric Summary: This diff ensures that ReactInstanceManager has a valid catalystInstance when updating views as part of the animation system. This also force the update of views to be posted in the UI Thread Changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D18311782 fbshipit-source-id: 1f1e7b0d34346f34b3607e5b75e5c14cda3f4861 --- .../react/uimanager/UIManagerModule.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index cdd8f98e9fe..f0a8910de05 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -469,7 +469,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule } @ReactMethod - public void updateView(int tag, String className, ReadableMap props) { + public void updateView(final int tag, final String className, final ReadableMap props) { if (DEBUG) { String message = "(UIManager.updateView) tag: " + tag + ", class: " + className + ", props: " + props; @@ -478,10 +478,19 @@ public class UIManagerModule extends ReactContextBaseJavaModule } int uiManagerType = ViewUtil.getUIManagerType(tag); if (uiManagerType == FABRIC) { - UIManager fabricUIManager = - UIManagerHelper.getUIManager(getReactApplicationContext(), uiManagerType); - if (fabricUIManager != null) { - fabricUIManager.synchronouslyUpdateViewOnUIThread(tag, props); + ReactApplicationContext reactApplicationContext = getReactApplicationContext(); + if (reactApplicationContext.hasActiveCatalystInstance()) { + final UIManager fabricUIManager = + UIManagerHelper.getUIManager(reactApplicationContext, uiManagerType); + if (fabricUIManager != null) { + reactApplicationContext.runOnUiQueueThread( + new Runnable() { + @Override + public void run() { + fabricUIManager.synchronouslyUpdateViewOnUIThread(tag, props); + } + }); + } } } else { mUIImplementation.updateView(tag, className, props);