From 1d878b2db481842147a8bcfe67258285fa39a30c Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Sun, 29 Oct 2023 16:40:30 -0700 Subject: [PATCH] Add support for legacy UIManager in UIManagerHelper (#41206) Summary: Root cause: Currently Bridgeless only support FabricUIManager and the legacy UIManager is not supported Next steps: check for other places where legacy UIManager is not supported Changelog: [Android][Changed] - Bridgeless: Add support for legacy UIManager in UIManagerHelper Reviewed By: cortinico Differential Revision: D50694805 --- .../react/uimanager/UIManagerHelper.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java index c4a3902d1e3d6a..e60538fda9f8d9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java @@ -22,9 +22,9 @@ import com.facebook.react.bridge.ReactNoCrashSoftException; import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.UIManager; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.uimanager.common.UIManagerType; import com.facebook.react.uimanager.events.EventDispatcher; -import com.facebook.react.uimanager.events.EventDispatcherProvider; /** Helper class for {@link UIManager}. */ public class UIManagerHelper { @@ -53,13 +53,19 @@ private static UIManager getUIManager( @UIManagerType int uiManagerType, boolean returnNullIfCatalystIsInactive) { if (context.isBridgeless()) { - @Nullable UIManager uiManager = (UIManager) context.getJSIModule(JSIModuleType.UIManager); + UIManager uiManager = null; + if (uiManagerType == FABRIC) { + uiManager = (UIManager) context.getJSIModule(JSIModuleType.UIManager); + } else if (ReactFeatureFlags.unstable_useFabricInterop) { + // When Fabric Interop is enabled in Bridgeless mode, enable the legacy UIManager + uiManager = context.getNativeModule(UIManagerModule.class); + } + if (uiManager == null) { ReactSoftExceptionLogger.logSoftException( TAG, new ReactNoCrashSoftException( "Cannot get UIManager because the instance hasn't been initialized yet.")); - return null; } return uiManager; } @@ -118,13 +124,6 @@ public static EventDispatcher getEventDispatcherForReactTag(ReactContext context @Nullable public static EventDispatcher getEventDispatcher( ReactContext context, @UIManagerType int uiManagerType) { - // TODO T67518514 Clean this up once we migrate everything over to bridgeless mode - if (context.isBridgeless()) { - if (context instanceof ThemedReactContext) { - context = ((ThemedReactContext) context).getReactApplicationContext(); - } - return ((EventDispatcherProvider) context).getEventDispatcher(); - } UIManager uiManager = getUIManager(context, uiManagerType, false); if (uiManager == null) { ReactSoftExceptionLogger.logSoftException(