Skip to content

Commit

Permalink
Adding getFabricUIManager() APIs to ReactContext
Browse files Browse the repository at this point in the history
Summary: Adding APIs for `getFabricUIManager()` to ReactContext and it's subclasses. This will replace the `getJSIModule()` post JSI module deletion.

Differential Revision: D51718430
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Nov 30, 2023
1 parent c98fa9c commit df9cfe1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -554,6 +555,25 @@ public boolean isBridgeless() {
return mCatalystInstance.getJSIModule(moduleType);
}

@DeprecatedInNewArchitecture(
message =
"This method will be deprecated later as part of Stable APIs with bridge removal and not encouraged usage.")
/**
* Get the UIManager for Fabric from the CatalystInstance.
*
* @return The UIManager when CatalystInstance is active.
*/
public @Nullable UIManager getFabricUIManager() {
if (!hasActiveReactInstance()) {
throw new IllegalStateException(
"Unable to retrieve a UIManager if CatalystInstance is not active.");
}
UIManager uiManager = mCatalystInstance.getFabricUIManager();
return uiManager != null
? uiManager
: (UIManager) mCatalystInstance.getJSIModule(JSIModuleType.UIManager);
}

/**
* Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed for
* compatibility with bridgeless mode, which has no CatalystInstance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactNoCrashBridgeNotAllowedSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
Expand Down Expand Up @@ -84,6 +85,11 @@ public void setSourceURL(String sourceURL) {
+ moduleType.name());
}

@Override
public @Nullable UIManager getFabricUIManager() {
return mReactHost.getUIManager();
}

@Override
public CatalystInstance getCatalystInstance() {
ReactSoftExceptionLogger.logSoftExceptionVerbose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UIManager;

/**
* Wraps {@link ReactContext} with the base {@link Context} passed into the constructor. It provides
Expand Down Expand Up @@ -116,4 +117,12 @@ public JSIModule getJSIModule(JSIModuleType moduleType) {
}
return super.getJSIModule(moduleType);
}

@Override
public UIManager getFabricUIManager() {
if (isBridgeless()) {
return mReactApplicationContext.getFabricUIManager();
}
return super.getFabricUIManager();
}
}

0 comments on commit df9cfe1

Please sign in to comment.