Skip to content

Commit 877dfad

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 a392dec commit 877dfad

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public boolean shouldShowDevMenuOrReload(int keyCode, KeyEvent event) {
148148
Assertions.assertNotNull(mDoubleTapReloadRecognizer)
149149
.didDoubleTapR(keyCode, mActivity.getCurrentFocus());
150150
if (didDoubleTapR) {
151-
getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();
151+
getReactNativeHost().getReactInstanceManager().getDevSupportManager().reloadExpoApp();
152152
return true;
153153
}
154154
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public BridgeDevSupportManager(
107107
}
108108
}
109109

110-
addCustomDevOption(
110+
expo_transformer_remove: addCustomDevOption(
111111
mIsSamplingProfilerEnabled ? "Disable Sampling Profiler" : "Enable Sampling Profiler",
112112
new DevOptionHandler() {
113113
@Override

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

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

87-
public static final String EMOJI_HUNDRED_POINTS_SYMBOL = " \uD83D\uDCAF";
88-
public static final String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " \uD83D\uDE45";
87+
public static String EMOJI_HUNDRED_POINTS_SYMBOL = " 💯";
88+
public static String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " 🙅";
8989

9090
private final Context mApplicationContext;
9191
private final ShakeDetector mShakeDetector;
@@ -375,6 +375,25 @@ public void run() {
375375
});
376376
}
377377

378+
private int getExponentActivityId() {
379+
return -1;
380+
}
381+
382+
@Override
383+
public void reloadExpoApp() {
384+
try {
385+
Class.forName("host.exp.exponent.ReactNativeStaticHelpers").getMethod("reloadFromManifest", int.class).invoke(null, getExponentActivityId());
386+
} catch (Exception expoHandleErrorException) {
387+
expoHandleErrorException.printStackTrace();
388+
389+
// reloadExpoApp replaces handleReloadJS in some places
390+
// where in Expo we would like to reload from manifest.
391+
// If so, if anything goes wrong here, we can fall back
392+
// to plain JS reload.
393+
handleReloadJS();
394+
}
395+
}
396+
378397
@Override
379398
public void showDevOptionsDialog() {
380399
if (mDevOptionsDialog != null || !mIsDevSupportEnabled || ActivityManager.isUserAMonkey()) {
@@ -396,7 +415,10 @@ public void onOptionSelected() {
396415
.show();
397416
mDevSettings.setHotModuleReplacementEnabled(false);
398417
}
399-
handleReloadJS();
418+
419+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
420+
// handleReloadJS();
421+
reloadExpoApp();
400422
}
401423
});
402424

@@ -434,7 +456,8 @@ public void onOptionSelected() {
434456
});
435457
}
436458

437-
options.put(
459+
// NOTE(brentvatne): This option does not make sense for Expo
460+
expo_transformer_remove: options.put(
438461
mApplicationContext.getString(R.string.reactandroid_catalyst_change_bundle_location),
439462
new DevOptionHandler() {
440463
@Override
@@ -498,7 +521,7 @@ public void onOptionSelected() {
498521
mCurrentContext.getJSModule(HMRClient.class).disable();
499522
}
500523
}
501-
if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
524+
expo_transformer_remove: if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
502525
Toast.makeText(
503526
mApplicationContext,
504527
mApplicationContext.getString(R.string.reactandroid_catalyst_hot_reloading_auto_enable),
@@ -529,7 +552,7 @@ public void onOptionSelected() {
529552
mDevSettings.setFpsDebugEnabled(!mDevSettings.isFpsDebugEnabled());
530553
}
531554
});
532-
options.put(
555+
expo_transformer_remove: options.put(
533556
mApplicationContext.getString(R.string.reactandroid_catalyst_settings),
534557
new DevOptionHandler() {
535558
@Override
@@ -1121,6 +1144,7 @@ public void run() {
11211144
});
11221145
}
11231146

1147+
// NOTE(brentvatne): this is confusingly called the first time the app loads!
11241148
private void reload() {
11251149
UiThreadUtil.assertOnUiThread();
11261150

@@ -1172,7 +1196,9 @@ public void onPackagerReloadCommand() {
11721196
new Runnable() {
11731197
@Override
11741198
public void run() {
1175-
handleReloadJS();
1199+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
1200+
// handleReloadJS();
1201+
reloadExpoApp();
11761202
}
11771203
});
11781204
}

packages/react-native/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

packages/react-native/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);

packages/react-native/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
}

packages/react-native/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)