File tree Expand file tree Collapse file tree
packages/react-native/ReactAndroid
main/java/com/facebook/react/runtime
test/java/com/facebook/react/runtime Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3570,7 +3570,7 @@ public abstract class com/facebook/react/runtime/BindingsInstaller {
35703570}
35713571
35723572public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/facebook/react/bridge/CatalystInstance {
3573- public fun <init> ()V
3573+ public fun <init> (Lcom/facebook/react/runtime/ReactHostImpl; )V
35743574 public fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
35753575 public fun addJSIModules (Ljava/util/List;)V
35763576 public fun callFunction (Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/NativeArray;)V
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHol
3232
3333@DoNotStrip
3434@DeprecatedInNewArchitecture
35- public class BridgelessCatalystInstance : CatalystInstance {
35+ public class BridgelessCatalystInstance (private val reactHost : ReactHostImpl ) : CatalystInstance {
36+
3637 override fun handleMemoryPressure (level : Int ) {
3738 throw UnsupportedOperationException (" Unimplemented method 'handleMemoryPressure'" )
3839 }
@@ -161,8 +162,8 @@ public class BridgelessCatalystInstance : CatalystInstance {
161162 throw UnsupportedOperationException (" Unimplemented method 'addJSIModules'" )
162163 }
163164
164- override fun getJSCallInvokerHolder (): CallInvokerHolder {
165- throw UnsupportedOperationException ( " Unimplemented method ' getJSCallInvokerHolder' " )
165+ override fun getJSCallInvokerHolder (): CallInvokerHolder ? {
166+ return reactHost. getJSCallInvokerHolder( )
166167 }
167168
168169 override fun getNativeMethodCallInvokerHolder (): NativeMethodCallInvokerHolder {
Original file line number Diff line number Diff line change 88package com .facebook .react .runtime ;
99
1010import android .content .Context ;
11+ import android .util .Log ;
1112import com .facebook .infer .annotation .Nullsafe ;
1213import com .facebook .react .bridge .Arguments ;
1314import com .facebook .react .bridge .Callback ;
1819import com .facebook .react .bridge .NativeArray ;
1920import com .facebook .react .bridge .NativeModule ;
2021import com .facebook .react .bridge .ReactApplicationContext ;
21- import com .facebook .react .bridge .ReactNoCrashBridgeNotAllowedSoftException ;
22- import com .facebook .react .bridge .ReactSoftExceptionLogger ;
2322import com .facebook .react .bridge .RuntimeExecutor ;
2423import com .facebook .react .bridge .UIManager ;
2524import com .facebook .react .bridge .WritableNativeArray ;
@@ -84,11 +83,10 @@ public void setSourceURL(String sourceURL) {
8483
8584 @ Override
8685 public CatalystInstance getCatalystInstance () {
87- ReactSoftExceptionLogger . logSoftExceptionVerbose (
86+ Log . w (
8887 TAG ,
89- new ReactNoCrashBridgeNotAllowedSoftException (
90- "getCatalystInstance() cannot be called when the bridge is disabled" ));
91- throw new UnsupportedOperationException ("There is no Catalyst instance in bridgeless mode." );
88+ "[WARNING] Bridgeless doesn't support CatalystInstance. Accessing an API that's not part of the new architecture is not encouraged usage." );
89+ return new BridgelessCatalystInstance (mReactHost );
9290 }
9391
9492 @ Override
Original file line number Diff line number Diff line change 6161import com .facebook .react .runtime .internal .bolts .Continuation ;
6262import com .facebook .react .runtime .internal .bolts .Task ;
6363import com .facebook .react .runtime .internal .bolts .TaskCompletionSource ;
64+ import com .facebook .react .turbomodule .core .interfaces .CallInvokerHolder ;
6465import com .facebook .react .uimanager .UIManagerModule ;
6566import com .facebook .react .uimanager .events .BlackHoleEventDispatcher ;
6667import com .facebook .react .uimanager .events .EventDispatcher ;
@@ -604,6 +605,20 @@ RuntimeExecutor getRuntimeExecutor() {
604605 return null ;
605606 }
606607
608+ /* package */
609+ @ Nullable
610+ CallInvokerHolder getJSCallInvokerHolder () {
611+ final ReactInstance reactInstance = mReactInstanceTaskRef .get ().getResult ();
612+ if (reactInstance != null ) {
613+ return reactInstance .getJSCallInvokerHolder ();
614+ }
615+ ReactSoftExceptionLogger .logSoftException (
616+ TAG ,
617+ new ReactNoCrashSoftException (
618+ "Tried to get JSCallInvokerHolder while instance is not ready" ));
619+ return null ;
620+ }
621+
607622 /**
608623 * To be called when the host activity receives an activity result.
609624 *
Original file line number Diff line number Diff line change @@ -461,7 +461,7 @@ private native HybridData initHybrid(
461461
462462 private native void loadJSBundleFromAssets (AssetManager assetManager , String assetURL );
463463
464- private native CallInvokerHolderImpl getJSCallInvokerHolder ();
464+ /* package */ native CallInvokerHolderImpl getJSCallInvokerHolder ();
465465
466466 private native NativeMethodCallInvokerHolderImpl getNativeMethodCallInvokerHolder ();
467467
Original file line number Diff line number Diff line change @@ -55,9 +55,11 @@ class BridgelessReactContextTest {
5555 Assertions .assertThat(bridgelessReactContext.getFabricUIManager()).isEqualTo(fabricUiManager)
5656 }
5757
58- @Test(expected = UnsupportedOperationException ::class )
59- fun getCatalystInstance_throwsException () {
60- // Disable this test for now due to mocking FabricUIManager fails
61- bridgelessReactContext.catalystInstance
58+ @Test
59+ fun getCatalystInstanceTest () {
60+ val bridgelessCatalystInstance = BridgelessCatalystInstance (reactHost)
61+ doReturn(bridgelessCatalystInstance).`when `(bridgelessReactContext).getCatalystInstance()
62+ Assertions .assertThat(bridgelessReactContext.getCatalystInstance())
63+ .isEqualTo(bridgelessCatalystInstance)
6264 }
6365}
You can’t perform that action at this time.
0 commit comments