Skip to content

Commit 56631cd

Browse files
Kudocipolleschi
authored andcommitted
fix ReactActivity.getReactDelegate().reload() (#44223)
Summary: fixing some problem for `ReactActivity.getReactDelegate().reload()` from #43521: - the `reload()` does not work for bridge mode on release build [ANDROID] [FIXED] - Fixed app reloading for `ReactActivity.getReactDelegate().reload()`. Pull Request resolved: #44223 Test Plan: tried to temporary change toast.show as reload and test from rn-tester ```diff --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt @@ -10,6 +10,7 @@ package com.facebook.react.modules.toast import android.view.Gravity import android.widget.Toast import com.facebook.fbreact.specs.NativeToastAndroidSpec +import com.facebook.react.ReactActivity import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.UiThreadUtil @@ -30,9 +31,11 @@ public class ToastModule(reactContext: ReactApplicationContext) : ) override public fun show(message: String?, durationDouble: Double) { - val duration = durationDouble.toInt() - UiThreadUtil.runOnUiThread( - Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() }) +// val duration = durationDouble.toInt() +// UiThreadUtil.runOnUiThread( +// Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() }) + val activity = reactApplicationContext.currentActivity as? ReactActivity + activity?.reactDelegate?.reload() } override public fun showWithGravity( ``` tried for different mode - [x] bridge mode + debug build - [x] bridgeless mode + debug build - [x] bridge mode + release build - [x] bridgeless mode + release build Reviewed By: fkgozali Differential Revision: D56795975 Pulled By: arushikesarwani94 fbshipit-source-id: 895eab1927ba6db748ebb32c0fd5313f19cf9d1b
1 parent cc1c697 commit 56631cd

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import androidx.annotation.NonNull;
1616
import androidx.annotation.Nullable;
1717
import com.facebook.infer.annotation.Assertions;
18+
import com.facebook.react.bridge.UiThreadUtil;
1819
import com.facebook.react.config.ReactFeatureFlags;
1920
import com.facebook.react.devsupport.DisabledDevSupportManager;
2021
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
@@ -99,7 +100,7 @@ private DevSupportManager getDevSupportManager() {
99100
&& mReactHost.getDevSupportManager() != null) {
100101
return mReactHost.getDevSupportManager();
101102
} else if (getReactNativeHost().hasInstance()
102-
&& getReactNativeHost().getUseDeveloperSupport()) {
103+
&& getReactNativeHost().getReactInstanceManager() != null) {
103104
return getReactNativeHost().getReactInstanceManager().getDevSupportManager();
104105
} else {
105106
return null;
@@ -241,17 +242,31 @@ public boolean onKeyLongPress(int keyCode) {
241242

242243
public void reload() {
243244
DevSupportManager devSupportManager = getDevSupportManager();
244-
if (devSupportManager != null) {
245-
// With Bridgeless enabled, reload in RELEASE mode
246-
if (devSupportManager instanceof DisabledDevSupportManager
247-
&& ReactFeatureFlags.enableBridgelessArchitecture
248-
&& mReactHost != null) {
249-
// Do not reload the bundle from JS as there is no bundler running in release mode.
250-
mReactHost.reload("ReactDelegate.reload()");
245+
if (devSupportManager == null) {
246+
return;
247+
}
248+
249+
// Reload in RELEASE mode
250+
if (devSupportManager instanceof ReleaseDevSupportManager) {
251+
// Do not reload the bundle from JS as there is no bundler running in release mode.
252+
if (ReactFeatureFlags.enableBridgelessArchitecture) {
253+
if (mReactHost != null) {
254+
mReactHost.reload("ReactDelegate.reload()");
255+
}
251256
} else {
252-
devSupportManager.handleReloadJS();
257+
UiThreadUtil.runOnUiThread(
258+
() -> {
259+
if (mReactNativeHost.hasInstance()
260+
&& mReactNativeHost.getReactInstanceManager() != null) {
261+
mReactNativeHost.getReactInstanceManager().recreateReactContextInBackground();
262+
}
263+
});
253264
}
265+
return;
254266
}
267+
268+
// Reload in DEBUG mode
269+
devSupportManager.handleReloadJS();
255270
}
256271

257272
public void loadApp() {

0 commit comments

Comments
 (0)