Skip to content

Commit

Permalink
Make events work for Fabric Interop on Bridgeless (facebook#40941)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#40941

Events are currently not working for Fabric Interop on Bridgeless. That's because the `BridgelessReactContext` is not checking for interop modules on `getJsModule` calls, so the `InteropEventEmitter` is never returned.

This extends `BridgelessReactContext` so that  `InteropEventEmitter` is returned if the Interop Layer is turned on.

Changelog:
[Internal] [Changed] - Make events work for Fabric Interop on Bridgeless

Reviewed By: cipolleschi

Differential Revision: D50266484

fbshipit-source-id: 0188d71bdc7acc8c188d886d45f0258914ad7af7
  • Loading branch information
cortinico authored and Othinn committed Oct 30, 2023
1 parent 62d9cd7 commit b28706e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface RCTDeviceEventEmitter extends JavaScriptModule {
private @Nullable JSExceptionHandler mExceptionHandlerWrapper;
private @Nullable WeakReference<Activity> mCurrentActivity;

private @Nullable InteropModuleRegistry mInteropModuleRegistry;
protected @Nullable InteropModuleRegistry mInteropModuleRegistry;
private boolean mIsInitialized = false;

public ReactContext(Context base) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.react.bridge.ReactNoCrashBridgeNotAllowedSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.uimanager.events.EventDispatcher;
Expand Down Expand Up @@ -49,6 +50,9 @@ class BridgelessReactContext extends ReactApplicationContext implements EventDis
BridgelessReactContext(Context context, ReactHostImpl host) {
super(context);
mReactHost = host;
if (ReactFeatureFlags.unstable_useFabricInterop) {
initializeInteropModules();
}
}

@Override
Expand Down Expand Up @@ -124,6 +128,10 @@ public BridgelessJSModuleInvocationHandler(

@Override
public <T extends JavaScriptModule> T getJSModule(Class<T> jsInterface) {
if (mInteropModuleRegistry != null
&& mInteropModuleRegistry.shouldReturnInteropModule(jsInterface)) {
return mInteropModuleRegistry.getInteropModule(jsInterface);
}
JavaScriptModule interfaceProxy =
(JavaScriptModule)
Proxy.newProxyInstance(
Expand Down

0 comments on commit b28706e

Please sign in to comment.