Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement getJSCallInvokerHolder for BridgelessCatalystInstance #43400

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ public abstract class com/facebook/react/runtime/BindingsInstaller {
}

public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/facebook/react/bridge/CatalystInstance {
public fun <init> ()V
public fun <init> (Lcom/facebook/react/runtime/ReactHostImpl;)V
public fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
public fun addJSIModules (Ljava/util/List;)V
public fun callFunction (Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/NativeArray;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHol

@DoNotStrip
@DeprecatedInNewArchitecture
public class BridgelessCatalystInstance : CatalystInstance {
public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) : CatalystInstance {

override fun handleMemoryPressure(level: Int) {
throw UnsupportedOperationException("Unimplemented method 'handleMemoryPressure'")
}
Expand Down Expand Up @@ -161,8 +162,8 @@ public class BridgelessCatalystInstance : CatalystInstance {
throw UnsupportedOperationException("Unimplemented method 'addJSIModules'")
}

override fun getJSCallInvokerHolder(): CallInvokerHolder {
throw UnsupportedOperationException("Unimplemented method 'getJSCallInvokerHolder'")
override fun getJSCallInvokerHolder(): CallInvokerHolder? {
return reactHost.getJSCallInvokerHolder()
}

override fun getNativeMethodCallInvokerHolder(): NativeMethodCallInvokerHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react.runtime;

import android.content.Context;
import android.util.Log;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
Expand All @@ -18,8 +19,6 @@
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactNoCrashBridgeNotAllowedSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.WritableNativeArray;
Expand Down Expand Up @@ -84,11 +83,10 @@ public void setSourceURL(String sourceURL) {

@Override
public CatalystInstance getCatalystInstance() {
ReactSoftExceptionLogger.logSoftExceptionVerbose(
Log.w(
TAG,
new ReactNoCrashBridgeNotAllowedSoftException(
"getCatalystInstance() cannot be called when the bridge is disabled"));
throw new UnsupportedOperationException("There is no Catalyst instance in bridgeless mode.");
"[WARNING] Bridgeless doesn't support CatalystInstance. Accessing an API that's not part of the new architecture is not encouraged usage.");
return new BridgelessCatalystInstance(mReactHost);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.facebook.react.runtime.internal.bolts.Continuation;
import com.facebook.react.runtime.internal.bolts.Task;
import com.facebook.react.runtime.internal.bolts.TaskCompletionSource;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.BlackHoleEventDispatcher;
import com.facebook.react.uimanager.events.EventDispatcher;
Expand Down Expand Up @@ -604,6 +605,20 @@ RuntimeExecutor getRuntimeExecutor() {
return null;
}

/* package */
@Nullable
CallInvokerHolder getJSCallInvokerHolder() {
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
if (reactInstance != null) {
return reactInstance.getJSCallInvokerHolder();
}
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Tried to get JSCallInvokerHolder while instance is not ready"));
return null;
}

/**
* To be called when the host activity receives an activity result.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private native HybridData initHybrid(

private native void loadJSBundleFromAssets(AssetManager assetManager, String assetURL);

private native CallInvokerHolderImpl getJSCallInvokerHolder();
/* package */ native CallInvokerHolderImpl getJSCallInvokerHolder();

private native NativeMethodCallInvokerHolderImpl getNativeMethodCallInvokerHolder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class BridgelessReactContextTest {
Assertions.assertThat(bridgelessReactContext.getFabricUIManager()).isEqualTo(fabricUiManager)
}

@Test(expected = UnsupportedOperationException::class)
fun getCatalystInstance_throwsException() {
// Disable this test for now due to mocking FabricUIManager fails
bridgelessReactContext.catalystInstance
@Test
fun getCatalystInstanceTest() {
val bridgelessCatalystInstance = BridgelessCatalystInstance(reactHost)
doReturn(bridgelessCatalystInstance).`when`(bridgelessReactContext).getCatalystInstance()
Assertions.assertThat(bridgelessReactContext.getCatalystInstance())
.isEqualTo(bridgelessCatalystInstance)
}
}
Loading