Skip to content

Commit

Permalink
fix ReactActivity.getReactDelegate().reload()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Apr 24, 2024
1 parent 849da21 commit 4f5dd70
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.KeyEvent;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
import com.facebook.react.devsupport.ReleaseDevSupportManager;
Expand Down Expand Up @@ -98,7 +99,7 @@ private DevSupportManager getDevSupportManager() {
&& mReactHost.getDevSupportManager() != null) {
return mReactHost.getDevSupportManager();
} else if (getReactNativeHost().hasInstance()
&& getReactNativeHost().getUseDeveloperSupport()) {
&& getReactNativeHost().getReactInstanceManager() != null) {
return getReactNativeHost().getReactInstanceManager().getDevSupportManager();
} else {
return null;
Expand Down Expand Up @@ -237,17 +238,29 @@ public boolean onKeyLongPress(int keyCode) {

public void reload() {
DevSupportManager devSupportManager = getDevSupportManager();
if (devSupportManager != null) {
// With Bridgeless enabled, reload in RELEASE mode
if (devSupportManager instanceof ReleaseDevSupportManager
&& ReactFeatureFlags.enableBridgelessArchitecture
&& mReactHost != null) {
// Do not reload the bundle from JS as there is no bundler running in release mode.
mReactHost.reload("ReactDelegate.reload()");
if (devSupportManager == null) {
return;
}

// Reload in RELEASE mode
if (devSupportManager instanceof ReleaseDevSupportManager) {
// Do not reload the bundle from JS as there is no bundler running in release mode.
if (ReactFeatureFlags.enableBridgelessArchitecture) {
if (mReactHost != null) {
mReactHost.reload("ReactDelegate.reload()");
}
} else {
devSupportManager.handleReloadJS();
UiThreadUtil.runOnUiThread(() -> {
if (mReactNativeHost.hasInstance() && mReactNativeHost.getReactInstanceManager() != null) {
mReactNativeHost.getReactInstanceManager().recreateReactContextInBackground();
}
});
}
return;
}

// Reload in DEBUG mode
devSupportManager.handleReloadJS();
}

public void loadApp() {
Expand Down

0 comments on commit 4f5dd70

Please sign in to comment.