Add a menu item for HMR
Summary: cc martinbigio Closes https://github.com/facebook/react-native/pull/5092 Reviewed By: svcscm Differential Revision: D2807241 Pulled By: mkonicek fb-gh-sync-id: e4418eeb4944d795f30f94be94b80648b4d7034c
This commit is contained in:
parent
daa93a6222
commit
5b3cb05fa8
|
@ -34,6 +34,7 @@ public class DevInternalSettings implements
|
|||
private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug";
|
||||
private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change";
|
||||
private static final String PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug";
|
||||
private static final String PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement";
|
||||
|
||||
private final SharedPreferences mPreferences;
|
||||
private final DevSupportManager mDebugManager;
|
||||
|
@ -77,6 +78,14 @@ public class DevInternalSettings implements
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isHotModuleReplacementEnabled() {
|
||||
return mPreferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, false);
|
||||
}
|
||||
|
||||
public void setHotModuleReplacementEnabled(boolean enabled) {
|
||||
mPreferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply();
|
||||
}
|
||||
|
||||
public boolean isReloadOnJSChangeEnabled() {
|
||||
return mPreferences.getBoolean(PREFS_RELOAD_ON_JS_CHANGE_KEY, false);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.facebook.common.logging.FLog;
|
|||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
|
||||
import com.squareup.okhttp.Call;
|
||||
import com.squareup.okhttp.Callback;
|
||||
import com.squareup.okhttp.ConnectionPool;
|
||||
|
@ -33,6 +32,7 @@ import com.squareup.okhttp.OkHttpClient;
|
|||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
|
||||
import okio.Okio;
|
||||
import okio.Sink;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class DevServerHelper {
|
|||
private static final String DEVICE_LOCALHOST = "localhost:8081";
|
||||
|
||||
private static final String BUNDLE_URL_FORMAT =
|
||||
"http://%s/%s.bundle?platform=android&dev=%s";
|
||||
"http://%s/%s.bundle?platform=android&dev=%s&hot=%s";
|
||||
private static final String SOURCE_MAP_URL_FORMAT =
|
||||
BUNDLE_URL_FORMAT.replaceFirst("\\.bundle", ".map");
|
||||
private static final String LAUNCH_CHROME_DEVTOOLS_COMMAND_URL_FORMAT =
|
||||
|
@ -120,12 +120,19 @@ public class DevServerHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return whether we should enabled dev mode or not when requesting JS bundles.
|
||||
* @return whether we should enable dev mode when requesting JS bundles.
|
||||
*/
|
||||
private boolean getDevMode() {
|
||||
return mSettings.isJSDevModeEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether we should enabled HMR when requesting JS bundles.
|
||||
*/
|
||||
private boolean getHMR() {
|
||||
return mSettings.isHotModuleReplacementEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the host to use when connecting to the bundle server.
|
||||
*/
|
||||
|
@ -160,15 +167,15 @@ public class DevServerHelper {
|
|||
return Build.FINGERPRINT.contains("generic");
|
||||
}
|
||||
|
||||
private static String createBundleURL(String host, String jsModulePath, boolean devMode) {
|
||||
return String.format(Locale.US, BUNDLE_URL_FORMAT, host, jsModulePath, devMode);
|
||||
private static String createBundleURL(String host, String jsModulePath, boolean devMode, boolean hmr) {
|
||||
return String.format(Locale.US, BUNDLE_URL_FORMAT, host, jsModulePath, devMode, hmr);
|
||||
}
|
||||
|
||||
public void downloadBundleFromURL(
|
||||
final BundleDownloadCallback callback,
|
||||
final String jsModulePath,
|
||||
final File outputFile) {
|
||||
final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode());
|
||||
final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode(), getHMR());
|
||||
Request request = new Request.Builder()
|
||||
.url(bundleURL)
|
||||
.build();
|
||||
|
@ -354,17 +361,17 @@ public class DevServerHelper {
|
|||
}
|
||||
|
||||
public String getSourceMapUrl(String mainModuleName) {
|
||||
return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode());
|
||||
return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR());
|
||||
}
|
||||
|
||||
public String getSourceUrl(String mainModuleName) {
|
||||
return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode());
|
||||
return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR());
|
||||
}
|
||||
|
||||
public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
|
||||
// The host IP we use when connecting to the JS bundle server from the emulator is not the
|
||||
// same as the one needed to connect to the same server from the Chrome proxy running on the
|
||||
// host itself.
|
||||
return createBundleURL(getHostForJSProxy(), mainModuleName, getDevMode());
|
||||
return createBundleURL(getHostForJSProxy(), mainModuleName, getDevMode(), getHMR());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,6 +262,17 @@ public class DevSupportManager implements NativeModuleCallExceptionHandler {
|
|||
handleReloadJS();
|
||||
}
|
||||
});
|
||||
options.put(
|
||||
mDevSettings.isHotModuleReplacementEnabled()
|
||||
? mApplicationContext.getString(R.string.catalyst_hot_module_replacement_off)
|
||||
: mApplicationContext.getString(R.string.catalyst_hot_module_replacement),
|
||||
new DevOptionHandler() {
|
||||
@Override
|
||||
public void onOptionSelected() {
|
||||
mDevSettings.setHotModuleReplacementEnabled(!mDevSettings.isHotModuleReplacementEnabled());
|
||||
handleReloadJS();
|
||||
}
|
||||
});
|
||||
options.put(
|
||||
mDevSettings.isReloadOnJSChangeEnabled()
|
||||
? mApplicationContext.getString(R.string.catalyst_live_reload_off)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
<string name="catalyst_reloadjs" project="catalyst" translatable="false">Reload JS</string>
|
||||
<string name="catalyst_debugjs" project="catalyst" translatable="false">Debug in Chrome</string>
|
||||
<string name="catalyst_debugjs_off" project="catalyst" translatable="false">Stop Chrome Debugging</string>
|
||||
<string name="catalyst_hot_module_replacement" project="catalyst" translatable="false">Enable Hot Module Replacement</string>
|
||||
<string name="catalyst_hot_module_replacement_off" project="catalyst" translatable="false">Disable Hot Module Replacement</string>
|
||||
<string name="catalyst_live_reload" project="catalyst" translatable="false">Enable Live Reload</string>
|
||||
<string name="catalyst_live_reload_off" project="catalyst" translatable="false">Disable Live Reload</string>
|
||||
<string name="catalyst_perf_monitor" project="catalyst" translatable="false">Enable Perf Monitor</string>
|
||||
|
|
Loading…
Reference in New Issue