Skip to content

Commit ebef72a

Browse files
alanjhugheschrfalch
authored andcommitted
reapply 65fdcab
1 parent 868e77c commit ebef72a

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
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
@@ -274,7 +274,7 @@ public void reload() {
274274
}
275275

276276
// Reload in DEBUG mode
277-
devSupportManager.handleReloadJS();
277+
devSupportManager.reloadExpoApp();
278278
}
279279

280280
/** Start the React surface with the app key supplied in the {@link ReactDelegate} constructor. */

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

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,47 @@ public abstract class DevSupportManagerBase(
300300
}
301301
}
302302

303+
private fun getExponentActivityId(): Int {
304+
return -1
305+
}
306+
307+
override fun reloadExpoApp() {
308+
try {
309+
val clazz = Class.forName("host.exp.exponent.ReactNativeStaticHelpers")
310+
val method = clazz.getMethod("reloadFromManifest", Int::class.javaPrimitiveType)
311+
method.invoke(null, getExponentActivityId())
312+
} catch (expoHandleErrorException: Exception) {
313+
expoHandleErrorException.printStackTrace()
314+
315+
// reloadExpoApp replaces handleReloadJS in some places
316+
// where in Expo we would like to reload from manifest.
317+
// If so, if anything goes wrong here, we can fall back
318+
// to plain JS reload.
319+
320+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
321+
reloadExpoApp()
322+
}
323+
}
324+
325+
303326
override fun showDevOptionsDialog() {
304327
if (devOptionsDialog != null || !isDevSupportEnabled || ActivityManager.isUserAMonkey()) {
305328
return
306329
}
307330
val options = LinkedHashMap<String, DevOptionHandler>()
308331
val disabledItemKeys: MutableSet<String?> = HashSet() /* register standard options */
309-
options[applicationContext.getString(R.string.catalyst_reload)] = DevOptionHandler {
310-
if (!devSettings.isJSDevModeEnabled && devSettings.isHotModuleReplacementEnabled) {
311-
Toast.makeText(
312-
applicationContext,
313-
applicationContext.getString(R.string.catalyst_hot_reloading_auto_disable),
314-
Toast.LENGTH_LONG)
315-
.show()
316-
devSettings.isHotModuleReplacementEnabled = false
317-
}
318-
handleReloadJS()
319-
}
332+
// NOTE(brentvatne): This option does not make sense for Expo
333+
// options[applicationContext.getString(R.string.catalyst_reload)] = DevOptionHandler {
334+
// if (!devSettings.isJSDevModeEnabled && devSettings.isHotModuleReplacementEnabled) {
335+
// Toast.makeText(
336+
// applicationContext,
337+
// applicationContext.getString(R.string.catalyst_hot_reloading_auto_disable),
338+
// Toast.LENGTH_LONG)
339+
// .show()
340+
// devSettings.isHotModuleReplacementEnabled = false
341+
// }
342+
// handleReloadJS()
343+
// }
320344

321345
if (devSettings.isDeviceDebugEnabled) {
322346
// On-device JS debugging (CDP). Render action to open debugger frontend.
@@ -369,15 +393,16 @@ public abstract class DevSupportManagerBase(
369393
reactContext.getJSModule(HMRClient::class.java)?.disable()
370394
}
371395
}
372-
if (nextEnabled && !devSettings.isJSDevModeEnabled) {
373-
Toast.makeText(
374-
applicationContext,
375-
applicationContext.getString(R.string.catalyst_hot_reloading_auto_enable),
376-
Toast.LENGTH_LONG)
377-
.show()
378-
devSettings.isJSDevModeEnabled = true
379-
handleReloadJS()
380-
}
396+
// NOTE(brentvatne): This option does not make sense for Expo
397+
// if (nextEnabled && !devSettings.isJSDevModeEnabled) {
398+
// Toast.makeText(
399+
// applicationContext,
400+
// applicationContext.getString(R.string.catalyst_hot_reloading_auto_enable),
401+
// Toast.LENGTH_LONG)
402+
// .show()
403+
// devSettings.isJSDevModeEnabled = true
404+
// handleReloadJS()
405+
// }
381406
}
382407

383408
val fpsDebugLabel =
@@ -396,11 +421,12 @@ public abstract class DevSupportManagerBase(
396421
}
397422
devSettings.isFpsDebugEnabled = !devSettings.isFpsDebugEnabled
398423
}
399-
options[applicationContext.getString(R.string.catalyst_settings)] = DevOptionHandler {
400-
val intent = Intent(applicationContext, DevSettingsActivity::class.java)
401-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
402-
applicationContext.startActivity(intent)
403-
}
424+
// NOTE(brentvatne): This option does not make sense for Expo
425+
// options[applicationContext.getString(R.string.catalyst_settings)] = DevOptionHandler {
426+
// val intent = Intent(applicationContext, DevSettingsActivity::class.java)
427+
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
428+
// applicationContext.startActivity(intent)
429+
// }
404430

405431
if (customDevOptions.isNotEmpty()) {
406432
options.putAll(customDevOptions)
@@ -752,6 +778,7 @@ public abstract class DevSupportManagerBase(
752778
}
753779
}
754780

781+
// NOTE(brentvatne): this is confusingly called the first time the app loads!
755782
private fun reload() {
756783
UiThreadUtil.assertOnUiThread()
757784

@@ -797,7 +824,11 @@ public abstract class DevSupportManagerBase(
797824
// Disable debugger to resume the JsVM & avoid thread locks while reloading
798825
devServerHelper.disableDebugger()
799826
}
800-
UiThreadUtil.runOnUiThread { handleReloadJS() }
827+
UiThreadUtil.runOnUiThread {
828+
// NOTE(brentvatne): rather than reload just JS we need to reload the entire project from manifest
829+
// handleReloadJS();
830+
reloadExpoApp();
831+
}
801832
}
802833

803834
override fun onPackagerDevMenuCommand() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ internal class RedBoxContentView(
199199
}
200200

201201
findViewById<Button>(R.id.rn_redbox_reload_button).setOnClickListener {
202-
devSupportManager.handleReloadJS()
202+
devSupportManager.reloadExpoApp()
203203
}
204204
findViewById<Button>(R.id.rn_redbox_dismiss_button).setOnClickListener {
205205
devSupportManager.hideRedboxDialog()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ internal class RedBoxDialogSurfaceDelegate(private val devSupportManager: DevSup
9595
return true
9696
}
9797
if (doubleTapReloadRecognizer.didDoubleTapR(keyCode, currentFocus)) {
98-
devSupportManager.handleReloadJS()
98+
devSupportManager.reloadExpoApp()
9999
}
100100
return super.onKeyUp(keyCode, event)
101101
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public open class ReleaseDevSupportManager : DevSupportManager {
9797

9898
public override fun handleReloadJS(): Unit = Unit
9999

100+
override public fun reloadExpoApp(): Unit = Unit
101+
100102
public override fun reloadJSFromServer(bundleURL: String, callback: BundleLoadCallback): Unit =
101103
Unit
102104

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt

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

6767
public fun handleReloadJS()
6868

69+
public fun reloadExpoApp(): Unit = Unit
70+
6971
public fun reloadJSFromServer(bundleURL: String, callback: BundleLoadCallback)
7072

7173
public fun isPackagerRunning(callback: PackagerStatusCallback)

0 commit comments

Comments
 (0)