diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 64acc925f464d2..95f69064a3888a 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -97,6 +97,7 @@ public abstract class com/facebook/react/ReactActivity : androidx/appcompat/app/ protected fun getMainComponentName ()Ljava/lang/String; public fun getReactActivityDelegate ()Lcom/facebook/react/ReactActivityDelegate; public fun getReactDelegate ()Lcom/facebook/react/ReactDelegate; + protected fun getReactHost ()Lcom/facebook/react/ReactHost; protected final fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager; protected final fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost; public fun invokeDefaultOnBackPressed ()V @@ -127,6 +128,7 @@ public class com/facebook/react/ReactActivityDelegate { protected fun getLaunchOptions ()Landroid/os/Bundle; public fun getMainComponentName ()Ljava/lang/String; protected fun getPlainActivity ()Landroid/app/Activity; + protected fun getReactActivity ()Lcom/facebook/react/ReactActivity; protected fun getReactDelegate ()Lcom/facebook/react/ReactDelegate; public fun getReactHost ()Lcom/facebook/react/ReactHost; public fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java index 864b0454d5d0f2..757ba90d5be7a7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java @@ -148,6 +148,10 @@ protected final ReactNativeHost getReactNativeHost() { return mDelegate.getReactNativeHost(); } + protected ReactHost getReactHost() { + return mDelegate.getReactHost(); + } + protected final ReactInstanceManager getReactInstanceManager() { return mDelegate.getReactInstanceManager(); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 8630a29723b000..766aa856cd803c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -76,8 +76,8 @@ public ReactActivityDelegate( } /** - * Get the {@link ReactNativeHost} used by this app. By default, assumes {@link - * Activity#getApplication()} is an instance of {@link ReactApplication} and calls {@link + * Get the {@link ReactNativeHost} used by this app with Bridge enabled. By default, assumes + * {@link Activity#getApplication()} is an instance of {@link ReactApplication} and calls {@link * ReactApplication#getReactNativeHost()}. Override this method if your application class does not * implement {@code ReactApplication} or you simply have a different mechanism for storing a * {@code ReactNativeHost}, e.g. as a static field somewhere. @@ -86,6 +86,13 @@ protected ReactNativeHost getReactNativeHost() { return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost(); } + /** + * Get the {@link ReactHost} used by this app with Bridgeless enabled. By default, assumes {@link + * Activity#getApplication()} is an instance of {@link ReactApplication} and calls {@link + * ReactApplication#getReactHost()}. Override this method if your application class does not + * implement {@code ReactApplication} or you simply have a different mechanism for storing a + * {@code ReactHost}, e.g. as a static field somewhere. + */ public ReactHost getReactHost() { return ((ReactApplication) getPlainActivity().getApplication()).getReactHost(); } @@ -226,6 +233,10 @@ protected Activity getPlainActivity() { return ((Activity) getContext()); } + protected ReactActivity getReactActivity() { + return ((ReactActivity) getContext()); + } + /** * Override this method if you wish to selectively toggle Fabric for a specific surface. This will * also control if Concurrent Root (React 18) should be enabled or not.