Skip to content

Commit

Permalink
Add support for legacy UIManager in UIManagerHelper (facebook#41206)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Oct 29, 2023
1 parent 118e651 commit 1d878b2
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1d878b2

Please sign in to comment.