From 2c88459e24af3a69d5e1058caefca1fbc0a4bc9d Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 10 Jun 2021 16:45:35 -0700 Subject: [PATCH] Refactor: Introduce methods to show/hide DevLoadingView in DevSupportManagerBase 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 --- .../devsupport/DevSupportManagerBase.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index 99fa2eedb62205..07c371e15aa40b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -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() @@ -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; } @@ -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(); } } @@ -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)); @@ -1140,8 +1153,7 @@ 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(); @@ -1149,8 +1161,7 @@ public void reloadJSFromServer(final String bundleURL, final BundleLoadCallback new DevBundleDownloadListener() { @Override public void onSuccess() { - mDevLoadingViewController.hide(); - mDevLoadingViewVisible = false; + hideDevLoadingView(); synchronized (DevSupportManagerBase.this) { mBundleStatus.isLastDownloadSucess = true; mBundleStatus.updateTimestamp = System.currentTimeMillis(); @@ -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; }