mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Add a debug support to load js bundle from external URL
Summary: Code refactoring on the dev support class. The idea is to make the code more modular. Reviewed By: mhorowitz Differential Revision: D4164676 fbshipit-source-id: 0d29bdaf927cd0e9f399fe6f8e46a16dfa65fb69
This commit is contained in:
parent
92fd0c2a5b
commit
72b517049a
@ -222,16 +222,19 @@ public class DevServerHelper {
|
||||
return String.format(Locale.US, RESOURCE_URL_FORMAT, host, resourcePath);
|
||||
}
|
||||
|
||||
public String getDevServerBundleURL(final String jsModulePath) {
|
||||
return createBundleURL(
|
||||
getDebugServerHost(),
|
||||
jsModulePath,
|
||||
getDevMode(),
|
||||
getHMR(),
|
||||
getJSMinifyMode());
|
||||
}
|
||||
|
||||
public void downloadBundleFromURL(
|
||||
final BundleDownloadCallback callback,
|
||||
final String jsModulePath,
|
||||
final File outputFile) {
|
||||
final String bundleURL = createBundleURL(
|
||||
getDebugServerHost(),
|
||||
jsModulePath,
|
||||
getDevMode(),
|
||||
getHMR(),
|
||||
getJSMinifyMode());
|
||||
final File outputFile,
|
||||
final String bundleURL) {
|
||||
final Request request = new Request.Builder()
|
||||
.url(bundleURL)
|
||||
.build();
|
||||
|
@ -45,6 +45,7 @@ public interface DevSupportManager extends NativeModuleCallExceptionHandler {
|
||||
boolean hasUpToDateJSBundleInCache();
|
||||
void reloadSettings();
|
||||
void handleReloadJS();
|
||||
void reloadJSFromServer(final String bundleURL);
|
||||
void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback);
|
||||
@Nullable File downloadBundleResourceFromUrlSync(
|
||||
final String resourceURL,
|
||||
|
@ -635,18 +635,12 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
||||
mRedBoxDialog.dismiss();
|
||||
}
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(mApplicationContext)
|
||||
.setTitle(R.string.catalyst_jsload_title)
|
||||
.setMessage(mApplicationContext.getString(
|
||||
mDevSettings.isRemoteJSDebugEnabled() ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message))
|
||||
.create();
|
||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
dialog.show();
|
||||
|
||||
if (mDevSettings.isRemoteJSDebugEnabled()) {
|
||||
reloadJSInProxyMode(dialog);
|
||||
reloadJSInProxyMode(showProgressDialog());
|
||||
} else {
|
||||
reloadJSFromServer(dialog);
|
||||
String bundleURL =
|
||||
mDevServerHelper.getDevServerBundleURL(Assertions.assertNotNull(mJSAppBundleName));
|
||||
reloadJSFromServer(bundleURL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -741,7 +735,22 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
||||
};
|
||||
}
|
||||
|
||||
private void reloadJSFromServer(final AlertDialog progressDialog) {
|
||||
private AlertDialog showProgressDialog() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(mApplicationContext)
|
||||
.setTitle(R.string.catalyst_jsload_title)
|
||||
.setMessage(mApplicationContext.getString(
|
||||
mDevSettings.isRemoteJSDebugEnabled() ?
|
||||
R.string.catalyst_remotedbg_message :
|
||||
R.string.catalyst_jsload_message))
|
||||
.create();
|
||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
dialog.show();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void reloadJSFromServer(final String bundleURL) {
|
||||
final AlertDialog progressDialog = showProgressDialog();
|
||||
|
||||
mDevServerHelper.downloadBundleFromURL(
|
||||
new DevServerHelper.BundleDownloadCallback() {
|
||||
@Override
|
||||
@ -776,8 +785,8 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
|
||||
});
|
||||
}
|
||||
},
|
||||
Assertions.assertNotNull(mJSAppBundleName),
|
||||
mJSBundleTempFile);
|
||||
mJSBundleTempFile,
|
||||
bundleURL);
|
||||
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
|
@ -126,6 +126,11 @@ public class DisabledDevSupportManager implements DevSupportManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadJSFromServer(String bundleURL) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isPackagerRunning(DevServerHelper.PackagerStatusCallback callback) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user