Skip to content

Commit

Permalink
Move loadSplitBundleFromServer from DevSupportManagerBase to BridgeDe…
Browse files Browse the repository at this point in the history
…vSupportManager

Summary:
## Rationale
DevSupportManagerBase.loadSplitBundleFromServer() uses the bridge. So, it's best to move it to DevSupportManagerBase.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D29004064

fbshipit-source-id: 9acfb769d57a44ee4871e1997ff0950c3d66b757
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 10, 2021
1 parent 3feaecd commit 3034089
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
Expand Up @@ -10,7 +10,9 @@
import android.content.Context;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.packagerconnection.RequestHandler;
import java.util.Map;

Expand Down Expand Up @@ -79,4 +81,26 @@ public BridgeDevSupportManager(
minNumShakes,
customPackagerCommandHandlers);
}

@Override
public void loadSplitBundleFromServer(
final String bundlePath, final DevSplitBundleCallback callback) {
fetchSplitBundleAndCreateBundleLoader(
bundlePath,
new CallbackWithBundleLoader() {
@Override
public void onSuccess(JSBundleLoader bundleLoader) {
bundleLoader.loadScript(getCurrentContext().getCatalystInstance());
getCurrentContext()
.getJSModule(HMRClient.class)
.registerBundle(getDevServerHelper().getDevServerSplitBundleURL(bundlePath));
callback.onSuccess();
}

@Override
public void onError(String url, Throwable cause) {
callback.onError(url, cause);
}
});
}
}
Expand Up @@ -46,7 +46,6 @@
import com.facebook.react.devsupport.interfaces.BundleLoadCallback;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.ErrorCustomizer;
import com.facebook.react.devsupport.interfaces.ErrorType;
Expand Down Expand Up @@ -98,7 +97,7 @@ public interface CallbackWithBundleLoader {
private final Context mApplicationContext;
private final ShakeDetector mShakeDetector;
private final BroadcastReceiver mReloadAppBroadcastReceiver;
protected final DevServerHelper mDevServerHelper;
private final DevServerHelper mDevServerHelper;
private final LinkedHashMap<String, DevOptionHandler> mCustomDevOptions = new LinkedHashMap<>();
private final ReactInstanceDevHelper mReactInstanceDevHelper;
private final @Nullable String mJSAppBundleName;
Expand Down Expand Up @@ -869,26 +868,12 @@ public void handleReloadJS() {
}
}

@Override
public void loadSplitBundleFromServer(
final String bundlePath, final DevSplitBundleCallback callback) {
fetchSplitBundleAndCreateBundleLoader(
bundlePath,
new CallbackWithBundleLoader() {
@Override
public void onSuccess(JSBundleLoader bundleLoader) {
bundleLoader.loadScript(mCurrentContext.getCatalystInstance());
mCurrentContext
.getJSModule(HMRClient.class)
.registerBundle(mDevServerHelper.getDevServerSplitBundleURL(bundlePath));
callback.onSuccess();
}
protected @Nullable ReactContext getCurrentContext() {
return mCurrentContext;
}

@Override
public void onError(String url, Throwable cause) {
callback.onError(url, cause);
}
});
protected DevServerHelper getDevServerHelper() {
return mDevServerHelper;
}

public void fetchSplitBundleAndCreateBundleLoader(
Expand Down

0 comments on commit 3034089

Please sign in to comment.