Add support for bridgeless mode to UIManagerHelper.getUIManager()

Summary:
`UIManagerHelper.getUIManager()` relies on the bridge (CatalystInstance) to get the proper UIManager depending on which renderer is being used. Unfortunately, this means it will always return null in bridgeless mode, where the CatalystInstance doesn't exist. This diff replaces the implementation of `BridgelessReactContext.getJSIModule()` to return the FabricUIManager from the ReactHost/Instance.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22480968

fbshipit-source-id: 640e3f22a5b39b315ed2f0397be3cba39e80529a
This commit is contained in:
Emily Janzer
2020-07-15 19:32:43 -07:00
committed by Facebook GitHub Bot
parent d61a8b7bb8
commit fc285f2f06
3 changed files with 27 additions and 1 deletions
@@ -445,7 +445,7 @@ public class ReactContext extends ContextWrapper {
return mCatalystInstance.getJavaScriptContextHolder();
}
public JSIModule getJSIModule(JSIModuleType moduleType) {
public @Nullable JSIModule getJSIModule(JSIModuleType moduleType) {
if (!hasActiveCatalystInstance()) {
throw new IllegalStateException(
"Unable to retrieve a JSIModule if CatalystInstance is not active.");
@@ -10,6 +10,8 @@ package com.facebook.react.uimanager;
import android.app.Activity;
import android.content.Context;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.JSIModule;
import com.facebook.react.bridge.JSIModuleType;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
@@ -77,4 +79,12 @@ public class ThemedReactContext extends ReactContext {
public boolean isBridgeless() {
return mReactApplicationContext.isBridgeless();
}
@Override
public JSIModule getJSIModule(JSIModuleType moduleType) {
if (isBridgeless()) {
return mReactApplicationContext.getJSIModule(moduleType);
}
return super.getJSIModule(moduleType);
}
}
@@ -51,6 +51,22 @@ public class UIManagerHelper {
ReactContext context,
@UIManagerType int uiManagerType,
boolean returnNullIfCatalystIsInactive) {
if (context.isBridgeless()) {
@Nullable
UIManager uiManager =
context.getJSIModule(JSIModuleType.UIManager) != null
? (UIManager) context.getJSIModule(JSIModuleType.UIManager)
: null;
if (uiManager == null) {
ReactSoftException.logSoftException(
"UIManagerHelper",
new ReactNoCrashSoftException(
"Cannot get UIManager because the instance hasn't been initialized yet."));
return null;
}
return uiManager;
}
if (!context.hasCatalystInstance()) {
ReactSoftException.logSoftException(
"UIManagerHelper",