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 23, 2024
1 parent ff094d8 commit 627b779
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ protected void onDestroy() {
mDelegate.onDestroy();
}

public void getReactDelegate() {
mDelegate.getReactDelegate();
public ReactDelegate getReactDelegate() {
return mDelegate.getReactDelegate();
}

public ReactActivityDelegate getReactActivityDelegate() {
Expand Down
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 627b779

Please sign in to comment.