Skip to content

Commit

Permalink
Refactor: Introduce methods to show/hide DevLoadingView in DevSupport…
Browse files Browse the repository at this point in the history
…ManagerBase

Summary:
## Rationale

Throughout DevSupportManagerBase, we show/hide the DevLoadingView and simultaneously write to the `mDevLoadingViewVisible` boolean. This diff pulls all those boolean writes into methods, so that subclasses of DevSupportManagerBase can show/hide the DevLoadingView without accessing the boolean directly.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D29004062

fbshipit-source-id: d54d79701e31f9ac8d1d1d44019199718fe1c8c0
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 10, 2021
1 parent 3034089 commit 2c88459
Showing 1 changed file with 26 additions and 16 deletions.
Expand Up @@ -856,8 +856,7 @@ public void handleReloadJS() {
if (mDevSettings.isRemoteJSDebugEnabled()) {
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: load from Proxy");
mDevLoadingViewController.showForRemoteJSEnabled();
mDevLoadingViewVisible = true;
showDevLoadingViewForRemoteJSEnabled();
reloadJSInProxyMode();
} else {
PrinterHolder.getPrinter()
Expand All @@ -872,6 +871,24 @@ public void handleReloadJS() {
return mCurrentContext;
}

@UiThread
private void showDevLoadingViewForUrl(String bundleUrl) {
mDevLoadingViewController.showForUrl(bundleUrl);
mDevLoadingViewVisible = true;
}

@UiThread
private void showDevLoadingViewForRemoteJSEnabled() {
mDevLoadingViewController.showForRemoteJSEnabled();
mDevLoadingViewVisible = true;
}

@UiThread
private void hideDevLoadingView() {
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
}

protected DevServerHelper getDevServerHelper() {
return mDevServerHelper;
}
Expand Down Expand Up @@ -938,16 +955,14 @@ public void run() {

@UiThread
private void showSplitBundleDevLoadingView(String bundleUrl) {
mDevLoadingViewController.showForUrl(bundleUrl);
mDevLoadingViewVisible = true;
showDevLoadingViewForUrl(bundleUrl);
mPendingJSSplitBundleRequests++;
}

@UiThread
private void hideSplitBundleDevLoadingView() {
if (--mPendingJSSplitBundleRequests == 0) {
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
hideDevLoadingView();
}
}

Expand Down Expand Up @@ -1105,14 +1120,12 @@ private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnect
@Override
public void onSuccess() {
future.set(true);
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
hideDevLoadingView();
}

@Override
public void onFailure(final Throwable cause) {
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
hideDevLoadingView();
FLog.e(ReactConstants.TAG, "Failed to connect to debugger!", cause);
future.setException(
new IOException(mApplicationContext.getString(R.string.catalyst_debug_error), cause));
Expand Down Expand Up @@ -1140,17 +1153,15 @@ public void run() {
public void reloadJSFromServer(final String bundleURL, final BundleLoadCallback callback) {
ReactMarker.logMarker(ReactMarkerConstants.DOWNLOAD_START);

mDevLoadingViewController.showForUrl(bundleURL);
mDevLoadingViewVisible = true;
showDevLoadingViewForUrl(bundleURL);

final BundleDownloader.BundleInfo bundleInfo = new BundleDownloader.BundleInfo();

mDevServerHelper.downloadBundleFromURL(
new DevBundleDownloadListener() {
@Override
public void onSuccess() {
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
hideDevLoadingView();
synchronized (DevSupportManagerBase.this) {
mBundleStatus.isLastDownloadSucess = true;
mBundleStatus.updateTimestamp = System.currentTimeMillis();
Expand All @@ -1175,8 +1186,7 @@ public void onProgress(

@Override
public void onFailure(final Exception cause) {
mDevLoadingViewController.hide();
mDevLoadingViewVisible = false;
hideDevLoadingView();
synchronized (DevSupportManagerBase.this) {
mBundleStatus.isLastDownloadSucess = false;
}
Expand Down

0 comments on commit 2c88459

Please sign in to comment.