Skip to content

Commit

Permalink
Refactor accessory show methods for DevLoading
Browse files Browse the repository at this point in the history
Summary:
Changelog:
    [Internal][Changed] - In order to make Dev Loading View cross platform, refactoring the accessary show methods.

Reviewed By: cortinico

Differential Revision: D41029102

fbshipit-source-id: 475949548fe98217e61d6cf64accbbdc0fb0f1c5
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Nov 7, 2022
1 parent 3d9a15d commit 7a327d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.facebook.react.R;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ReactConstants;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;

/** Controller to display loading messages on top of the screen. All methods are thread safe. */
Expand Down Expand Up @@ -55,34 +53,6 @@ public void run() {
});
}

public void showForUrl(String url) {
Context context = getContext();
if (context == null) {
return;
}

URL parsedURL;
try {
parsedURL = new URL(url);
} catch (MalformedURLException e) {
FLog.e(ReactConstants.TAG, "Bundle url format is invalid. \n\n" + e.toString());
return;
}

int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
showMessage(
context.getString(R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
}

public void showForRemoteJSEnabled() {
Context context = getContext();
if (context == null) {
return;
}

showMessage(context.getString(R.string.catalyst_debug_connecting));
}

public void updateProgress(
final @Nullable String status, final @Nullable Integer done, final @Nullable Integer total) {
if (!sEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,34 @@ protected ReactInstanceDevHelper getReactInstanceDevHelper() {

@UiThread
private void showDevLoadingViewForUrl(String bundleUrl) {
mDevLoadingViewController.showForUrl(bundleUrl);
if (mApplicationContext == null) {
return;
}

URL parsedURL;

try {
parsedURL = new URL(bundleUrl);
} catch (MalformedURLException e) {
FLog.e(ReactConstants.TAG, "Bundle url format is invalid. \n\n" + e.toString());
return;
}

int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
mDevLoadingViewController.showMessage(
mApplicationContext.getString(
R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
mDevLoadingViewVisible = true;
}

@UiThread
protected void showDevLoadingViewForRemoteJSEnabled() {
mDevLoadingViewController.showForRemoteJSEnabled();
if (mApplicationContext == null) {
return;
}

mDevLoadingViewController.showMessage(
mApplicationContext.getString(R.string.catalyst_debug_connecting));
mDevLoadingViewVisible = true;
}

Expand Down

0 comments on commit 7a327d9

Please sign in to comment.