Skip to content

Commit

Permalink
Fix port as -1 if dev server without specifying port on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Sep 16, 2022
1 parent 1cdeb20 commit 4beb8f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
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;
import okhttp3.HttpUrl;

/** Controller to display loading messages on top of the screen. All methods are thread safe. */
public class DevLoadingViewController {
Expand Down Expand Up @@ -61,17 +60,17 @@ public void showForUrl(String url) {
return;
}

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

showMessage(
context.getString(
R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + parsedURL.getPort()));
R.string.catalyst_loading_from_url, parsedURL.host() + ":" + parsedURL.port()));
}

public void showForRemoteJSEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@
import com.facebook.react.packagerconnection.RequestHandler;
import com.facebook.react.packagerconnection.Responder;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import okhttp3.HttpUrl;

public abstract class DevSupportManagerBase implements DevSupportManager {

Expand Down Expand Up @@ -700,14 +699,14 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) {

if (mCurrentContext != null) {
try {
URL sourceUrl = new URL(getSourceUrl());
String path = sourceUrl.getPath().substring(1); // strip initial slash in path
String host = sourceUrl.getHost();
int port = sourceUrl.getPort();
HttpUrl sourceUrl = HttpUrl.get(getSourceUrl());
String path = sourceUrl.encodedPath().substring(1); // strip initial slash in path
String host = sourceUrl.host();
int port = sourceUrl.port();
mCurrentContext
.getJSModule(HMRClient.class)
.setup("android", path, host, port, mDevSettings.isHotModuleReplacementEnabled());
} catch (MalformedURLException e) {
} catch (IllegalArgumentException e) {
showNewJavaError(e.getMessage(), e);
}
}
Expand Down

0 comments on commit 4beb8f6

Please sign in to comment.