From 62ebe557b8efbfb025f6187ef08a9c2223f4f3c3 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Thu, 21 Mar 2024 09:40:32 -0700 Subject: [PATCH] Expose ReactDelegate for react-native-restart (#43588) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43588 Supported `reload()` in Bridgeless through ReactDelegate in https://github.com/facebook/react-native/pull/43521 in order to unblock react-native-restart https://github.com/avishayil/react-native-restart/blob/134cabd5b3f355ffe551e5dd1be1dd46d870fe13/android/src/main/java/com/reactnativerestart/RestartModule.java#L54 which can access React Delegate through : ``` if(currentActivity instanceof ReactActivity) { ReactActivity reactActivity = (ReactActivity) currentActivity; ReactDelegate reactDelegate = reactActivity.getReactDelegate(); reactDelegate.reload() } ``` Changelog: [Android][Added] Expose ReactDelegate in ReactActivity Reviewed By: cortinico Differential Revision: D55166962 fbshipit-source-id: 5d8dfd7ad61edbcb5233014800eb66a538842ca5 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 2 ++ .../src/main/java/com/facebook/react/ReactActivity.java | 4 ++++ .../main/java/com/facebook/react/ReactActivityDelegate.java | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index adf3eb3283a28f..755f4d8d7a720e 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -83,6 +83,7 @@ public abstract class com/facebook/react/ReactActivity : androidx/appcompat/app/ protected fun ()V protected fun createReactActivityDelegate ()Lcom/facebook/react/ReactActivityDelegate; protected fun getMainComponentName ()Ljava/lang/String; + public fun getReactDelegate ()V protected final fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager; protected final fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost; public fun invokeDefaultOnBackPressed ()V @@ -113,6 +114,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 getReactDelegate ()Lcom/facebook/react/ReactDelegate; public fun getReactHost ()Lcom/facebook/react/ReactHost; public fun getReactInstanceManager ()Lcom/facebook/react/ReactInstanceManager; protected fun getReactNativeHost ()Lcom/facebook/react/ReactNativeHost; 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 0f5c8d01730fb6..cb7d1d9187518b 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 @@ -65,6 +65,10 @@ protected void onDestroy() { mDelegate.onDestroy(); } + public void getReactDelegate() { + mDelegate.getReactDelegate(); + } + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); 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 5c36282ba7c301..c1102ab469fc3b 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 @@ -87,6 +87,10 @@ public ReactHost getReactHost() { return ((ReactApplication) getPlainActivity().getApplication()).getReactHost(); } + protected @Nullable ReactDelegate getReactDelegate() { + return mReactDelegate; + } + public ReactInstanceManager getReactInstanceManager() { return mReactDelegate.getReactInstanceManager(); }