From 35c46b83af6f18aedfd07fa45c38b407db0b3bb3 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Tue, 9 Apr 2019 22:17:03 +0200 Subject: [PATCH 1/6] improve dev mode and HMR interop --- .../facebook/react/devsupport/DevSupportManagerImpl.java | 8 ++++++++ .../src/main/res/devsupport/xml/rn_dev_preferences.xml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 2d58c949ff3579..2691f25a558039 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -459,6 +459,10 @@ public void showDevOptionsDialog() { new DevOptionHandler() { @Override public void onOptionSelected() { + if (mDevSettings.isHotModuleReplacementEnabled()) { + Toast.makeText(mApplicationContext, "Dev mode and HRM cannot be both enabled at once. Disabling HMR...", Toast.LENGTH_LONG).show(); + mDevSettings.setHotModuleReplacementEnabled(false); + } handleReloadJS(); } }); @@ -509,6 +513,10 @@ public void onOptionSelected() { new DevOptionHandler() { @Override public void onOptionSelected() { + if (!mDevSettings.isJSDevModeEnabled()) { + Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HRM.", Toast.LENGTH_LONG).show(); + return; + } mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled()); handleReloadJS(); } diff --git a/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml b/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml index c9b1e616ee6e36..6208e4e88020c0 100644 --- a/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml +++ b/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml @@ -10,7 +10,7 @@ Date: Wed, 10 Apr 2019 22:32:21 +0200 Subject: [PATCH 2/6] improve error message --- .../facebook/react/devsupport/DevSupportManagerImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 2691f25a558039..6e0dcb8d0479f2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -459,8 +459,8 @@ public void showDevOptionsDialog() { new DevOptionHandler() { @Override public void onOptionSelected() { - if (mDevSettings.isHotModuleReplacementEnabled()) { - Toast.makeText(mApplicationContext, "Dev mode and HRM cannot be both enabled at once. Disabling HMR...", Toast.LENGTH_LONG).show(); + if (!mDevSettings.isJSDevModeEnabled() && mDevSettings.isHotModuleReplacementEnabled()) { + Toast.makeText(mApplicationContext, "HMR cannot be enabled when Dev mode is off. Disabling HMR...", Toast.LENGTH_LONG).show(); mDevSettings.setHotModuleReplacementEnabled(false); } handleReloadJS(); @@ -514,7 +514,7 @@ public void onOptionSelected() { @Override public void onOptionSelected() { if (!mDevSettings.isJSDevModeEnabled()) { - Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HRM.", Toast.LENGTH_LONG).show(); + Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HMR.", Toast.LENGTH_LONG).show(); return; } mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled()); From cafd9ec6844fb51a077cb05ed62da3454ebe746f Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Wed, 10 Apr 2019 22:36:47 +0200 Subject: [PATCH 3/6] explicitly check for HMR being turned on --- .../com/facebook/react/devsupport/DevSupportManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 6e0dcb8d0479f2..f0c54ad3f34981 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -513,7 +513,7 @@ public void onOptionSelected() { new DevOptionHandler() { @Override public void onOptionSelected() { - if (!mDevSettings.isJSDevModeEnabled()) { + if (!mDevSettings.isHotModuleReplacementEnabled() && !mDevSettings.isJSDevModeEnabled()) { Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HMR.", Toast.LENGTH_LONG).show(); return; } From eb1972b81652359eddb962525d81c8c3c201702c Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 11 Apr 2019 00:01:51 +0200 Subject: [PATCH 4/6] make message more actionable --- .../com/facebook/react/devsupport/DevSupportManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index f0c54ad3f34981..6892f25e619515 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -514,7 +514,7 @@ public void onOptionSelected() { @Override public void onOptionSelected() { if (!mDevSettings.isHotModuleReplacementEnabled() && !mDevSettings.isJSDevModeEnabled()) { - Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HMR.", Toast.LENGTH_LONG).show(); + Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HMR. Enable Dev mode first to enable HMR.", Toast.LENGTH_LONG).show(); return; } mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled()); From ddc8e3485c45b7843ae1ee0d500b02bceed10fa7 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 11 Apr 2019 00:07:32 +0200 Subject: [PATCH 5/6] add setJSDevModeEnabled without putting it in interface --- .../com/facebook/react/devsupport/DevInternalSettings.java | 4 ++++ .../com/facebook/react/devsupport/DevSupportManagerImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java index 4e18237ef7ca03..123b728d7cba50 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java @@ -88,6 +88,10 @@ public boolean isJSDevModeEnabled() { return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true); } + public void setJSDevModeEnabled(boolean value) { + mPreferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply(); + } + @Override public boolean isJSMinifyEnabled() { return mPreferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false); diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 6892f25e619515..d29fcb095eea3b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -514,8 +514,8 @@ public void onOptionSelected() { @Override public void onOptionSelected() { if (!mDevSettings.isHotModuleReplacementEnabled() && !mDevSettings.isJSDevModeEnabled()) { - Toast.makeText(mApplicationContext, "Dev mode needs to be turned on to enable HMR. Enable Dev mode first to enable HMR.", Toast.LENGTH_LONG).show(); - return; + Toast.makeText(mApplicationContext, "You're trying to enable HMR while Dev mode is off. Turning the Dev mode on...", Toast.LENGTH_LONG).show(); + mDevSettings.setJSDevModeEnabled(true); } mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled()); handleReloadJS(); From 2678f355cc0a72a8e4c5e7151e58059c3c24be68 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 11 Apr 2019 00:10:32 +0200 Subject: [PATCH 6/6] improve message --- .../com/facebook/react/devsupport/DevSupportManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index d29fcb095eea3b..b3643e77b74ad2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -514,7 +514,7 @@ public void onOptionSelected() { @Override public void onOptionSelected() { if (!mDevSettings.isHotModuleReplacementEnabled() && !mDevSettings.isJSDevModeEnabled()) { - Toast.makeText(mApplicationContext, "You're trying to enable HMR while Dev mode is off. Turning the Dev mode on...", Toast.LENGTH_LONG).show(); + Toast.makeText(mApplicationContext, "You're trying to enable HMR while Dev mode is off. Turning both HMR and the Dev mode on...", Toast.LENGTH_LONG).show(); mDevSettings.setJSDevModeEnabled(true); } mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled());