File tree Expand file tree Collapse file tree 6 files changed +31
-15
lines changed
packages/react-native/ReactAndroid
main/java/com/facebook/react/runtime
test/java/com/facebook/react/runtime Expand file tree Collapse file tree 6 files changed +31
-15
lines changed Original file line number Diff line number Diff line change @@ -3570,7 +3570,7 @@ public abstract class com/facebook/react/runtime/BindingsInstaller {
3570
3570
}
3571
3571
3572
3572
public 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
3574
3574
public fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
3575
3575
public fun addJSIModules (Ljava/util/List;)V
3576
3576
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
32
32
33
33
@DoNotStrip
34
34
@DeprecatedInNewArchitecture
35
- public class BridgelessCatalystInstance : CatalystInstance {
35
+ public class BridgelessCatalystInstance (private val reactHost : ReactHostImpl ) : CatalystInstance {
36
+
36
37
override fun handleMemoryPressure (level : Int ) {
37
38
throw UnsupportedOperationException (" Unimplemented method 'handleMemoryPressure'" )
38
39
}
@@ -161,8 +162,8 @@ public class BridgelessCatalystInstance : CatalystInstance {
161
162
throw UnsupportedOperationException (" Unimplemented method 'addJSIModules'" )
162
163
}
163
164
164
- override fun getJSCallInvokerHolder (): CallInvokerHolder {
165
- throw UnsupportedOperationException ( " Unimplemented method ' getJSCallInvokerHolder' " )
165
+ override fun getJSCallInvokerHolder (): CallInvokerHolder ? {
166
+ return reactHost. getJSCallInvokerHolder( )
166
167
}
167
168
168
169
override fun getNativeMethodCallInvokerHolder (): NativeMethodCallInvokerHolder {
Original file line number Diff line number Diff line change 8
8
package com .facebook .react .runtime ;
9
9
10
10
import android .content .Context ;
11
+ import android .util .Log ;
11
12
import com .facebook .infer .annotation .Nullsafe ;
12
13
import com .facebook .react .bridge .Arguments ;
13
14
import com .facebook .react .bridge .Callback ;
18
19
import com .facebook .react .bridge .NativeArray ;
19
20
import com .facebook .react .bridge .NativeModule ;
20
21
import com .facebook .react .bridge .ReactApplicationContext ;
21
- import com .facebook .react .bridge .ReactNoCrashBridgeNotAllowedSoftException ;
22
- import com .facebook .react .bridge .ReactSoftExceptionLogger ;
23
22
import com .facebook .react .bridge .RuntimeExecutor ;
24
23
import com .facebook .react .bridge .UIManager ;
25
24
import com .facebook .react .bridge .WritableNativeArray ;
@@ -84,11 +83,10 @@ public void setSourceURL(String sourceURL) {
84
83
85
84
@ Override
86
85
public CatalystInstance getCatalystInstance () {
87
- ReactSoftExceptionLogger . logSoftExceptionVerbose (
86
+ Log . w (
88
87
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 );
92
90
}
93
91
94
92
@ Override
Original file line number Diff line number Diff line change 61
61
import com .facebook .react .runtime .internal .bolts .Continuation ;
62
62
import com .facebook .react .runtime .internal .bolts .Task ;
63
63
import com .facebook .react .runtime .internal .bolts .TaskCompletionSource ;
64
+ import com .facebook .react .turbomodule .core .interfaces .CallInvokerHolder ;
64
65
import com .facebook .react .uimanager .UIManagerModule ;
65
66
import com .facebook .react .uimanager .events .BlackHoleEventDispatcher ;
66
67
import com .facebook .react .uimanager .events .EventDispatcher ;
@@ -604,6 +605,20 @@ RuntimeExecutor getRuntimeExecutor() {
604
605
return null ;
605
606
}
606
607
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
+
607
622
/**
608
623
* To be called when the host activity receives an activity result.
609
624
*
Original file line number Diff line number Diff line change @@ -461,7 +461,7 @@ private native HybridData initHybrid(
461
461
462
462
private native void loadJSBundleFromAssets (AssetManager assetManager , String assetURL );
463
463
464
- private native CallInvokerHolderImpl getJSCallInvokerHolder ();
464
+ /* package */ native CallInvokerHolderImpl getJSCallInvokerHolder ();
465
465
466
466
private native NativeMethodCallInvokerHolderImpl getNativeMethodCallInvokerHolder ();
467
467
Original file line number Diff line number Diff line change @@ -55,9 +55,11 @@ class BridgelessReactContextTest {
55
55
Assertions .assertThat(bridgelessReactContext.getFabricUIManager()).isEqualTo(fabricUiManager)
56
56
}
57
57
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)
62
64
}
63
65
}
You can’t perform that action at this time.
0 commit comments