Skip to content

Commit 394ecd6

Browse files
sjchmielabrentvatneesamelsonKudo
committed
[android] Always reload from manifest expo/expo#6134 honoring bare-expo and :tools:execute
Squashed three commits: - d8f3fbe - ae5e396 - 2217620 The first one introduced breaking changes for bare workflow in our React Native fork, the second one fixed them by integrating with ReactAndroidCodeTransformer used when we import the code into Expo Client, the third one added usage for `reloadExpoApp` to debugger UI. Co-Authored-By: brentvatne <[email protected]> Co-Authored-By: esamelson <[email protected]> Co-Authored-By: Kudo Chien <[email protected]>
1 parent 7186dae commit 394ecd6

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public boolean shouldShowDevMenuOrReload(int keyCode, KeyEvent event) {
129129
Assertions.assertNotNull(mDoubleTapReloadRecognizer)
130130
.didDoubleTapR(keyCode, mActivity.getCurrentFocus());
131131
if (didDoubleTapR) {
132-
getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();
132+
getReactNativeHost().getReactInstanceManager().getDevSupportManager().reloadExpoApp();
133133
return true;
134134
}
135135
}

ReactAndroid/src/main/java/com/facebook/react/devsupport/BridgeDevSupportManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public BridgeDevSupportManager(
9999
}
100100
}
101101

102-
addCustomDevOption(
102+
expo_transformer_remove: addCustomDevOption(
103103
mIsSamplingProfilerEnabled ? "Disable Sampling Profiler" : "Enable Sampling Profiler",
104104
new DevOptionHandler() {
105105
@Override

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public interface CallbackWithBundleLoader {
8282
private static final String EXOPACKAGE_LOCATION_FORMAT =
8383
"/data/local/tmp/exopackage/%s//secondary-dex";
8484

85-
public static final String EMOJI_HUNDRED_POINTS_SYMBOL = " \uD83D\uDCAF";
86-
public static final String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " \uD83D\uDE45";
85+
public static String EMOJI_HUNDRED_POINTS_SYMBOL = " 💯";
86+
public static String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " 🙅";
8787

8888
private final Context mApplicationContext;
8989
private final ShakeDetector mShakeDetector;
@@ -369,6 +369,25 @@ public void run() {
369369
});
370370
}
371371

372+
private int getExponentActivityId() {
373+
return -1;
374+
}
375+
376+
@Override
377+
public void reloadExpoApp() {
378+
try {
379+
Class.forName("host.exp.exponent.ReactNativeStaticHelpers").getMethod("reloadFromManifest", int.class).invoke(null, getExponentActivityId());
380+
} catch (Exception expoHandleErrorException) {
381+
expoHandleErrorException.printStackTrace();
382+
383+
// reloadExpoApp replaces handleReloadJS in some places
384+
// where in Expo we would like to reload from manifest.
385+
// If so, if anything goes wrong here, we can fall back
386+
// to plain JS reload.
387+
handleReloadJS();
388+
}
389+
}
390+
372391
@Override
373392
public void showDevOptionsDialog() {
374393
if (mDevOptionsDialog != null || !mIsDevSupportEnabled || ActivityManager.isUserAMonkey()) {
@@ -390,7 +409,10 @@ public void onOptionSelected() {
390409
.show();
391410
mDevSettings.setHotModuleReplacementEnabled(false);
392411
}
393-
handleReloadJS();
412+
413+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
414+
// handleReloadJS();
415+
reloadExpoApp();
394416
}
395417
});
396418

@@ -428,7 +450,8 @@ public void onOptionSelected() {
428450
});
429451
}
430452

431-
options.put(
453+
// NOTE(brentvatne): This option does not make sense for Expo
454+
expo_transformer_remove: options.put(
432455
mApplicationContext.getString(R.string.reactandroid_catalyst_change_bundle_location),
433456
new DevOptionHandler() {
434457
@Override
@@ -492,7 +515,7 @@ public void onOptionSelected() {
492515
mCurrentContext.getJSModule(HMRClient.class).disable();
493516
}
494517
}
495-
if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
518+
expo_transformer_remove: if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
496519
Toast.makeText(
497520
mApplicationContext,
498521
mApplicationContext.getString(R.string.reactandroid_catalyst_hot_reloading_auto_enable),
@@ -523,7 +546,7 @@ public void onOptionSelected() {
523546
mDevSettings.setFpsDebugEnabled(!mDevSettings.isFpsDebugEnabled());
524547
}
525548
});
526-
options.put(
549+
expo_transformer_remove: options.put(
527550
mApplicationContext.getString(R.string.reactandroid_catalyst_settings),
528551
new DevOptionHandler() {
529552
@Override
@@ -1077,6 +1100,7 @@ public void run() {
10771100
});
10781101
}
10791102

1103+
// NOTE(brentvatne): this is confusingly called the first time the app loads!
10801104
private void reload() {
10811105
UiThreadUtil.assertOnUiThread();
10821106

@@ -1128,7 +1152,9 @@ public void onPackagerReloadCommand() {
11281152
new Runnable() {
11291153
@Override
11301154
public void run() {
1131-
handleReloadJS();
1155+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
1156+
// handleReloadJS();
1157+
reloadExpoApp();
11321158
}
11331159
});
11341160
}

ReactAndroid/src/main/java/com/facebook/react/devsupport/DisabledDevSupportManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public void reloadSettings() {}
138138
@Override
139139
public void handleReloadJS() {}
140140

141+
@Override
142+
public void reloadExpoApp() {}
143+
141144
@Override
142145
public void reloadJSFromServer(String bundleURL) {}
143146

ReactAndroid/src/main/java/com/facebook/react/devsupport/RedBoxContentView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void init() {
259259
new View.OnClickListener() {
260260
@Override
261261
public void onClick(View v) {
262-
Assertions.assertNotNull(mDevSupportManager).handleReloadJS();
262+
Assertions.assertNotNull(mDevSupportManager).reloadExpoApp();
263263
}
264264
});
265265
mDismissButton = (Button) findViewById(R.id.rn_redbox_dismiss_button);

ReactAndroid/src/main/java/com/facebook/react/devsupport/RedBoxDialogSurfaceDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
9898
return true;
9999
}
100100
if (mDoubleTapReloadRecognizer.didDoubleTapR(keyCode, getCurrentFocus())) {
101-
mDevSupportManager.handleReloadJS();
101+
mDevSupportManager.reloadExpoApp();
102102
}
103103
return super.onKeyUp(keyCode, event);
104104
}

ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public interface DevSupportManager extends JSExceptionHandler {
7272

7373
void handleReloadJS();
7474

75+
void reloadExpoApp();
76+
7577
void reloadJSFromServer(final String bundleURL);
7678

7779
void reloadJSFromServer(final String bundleURL, final BundleLoadCallback callback);

0 commit comments

Comments
 (0)