mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add native module for loading split JS bundles in development
Reviewed By: mdvacca, cpojer Differential Revision: D22001709 fbshipit-source-id: 4e378fd6ae90268e7db9092a71628205b9f7c37d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2e2c881147
commit
fca3a39da5
@@ -0,0 +1,21 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "bundleloader",
|
||||
srcs = glob(["*.java"]),
|
||||
is_androidx = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
provided_deps = [
|
||||
react_native_dep("third-party/android/androidx:annotation"),
|
||||
],
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/common:common"),
|
||||
react_native_target("java/com/facebook/react/devsupport:interfaces"),
|
||||
react_native_target("java/com/facebook/react/module/annotations:annotations"),
|
||||
],
|
||||
exported_deps = [react_native_target("java/com/facebook/fbreact/specs:FBReactNativeSpec")],
|
||||
)
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.bundleloader;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.fbreact.specs.NativeDevSplitBundleLoaderSpec;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.common.DebugServerException;
|
||||
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
|
||||
@ReactModule(name = NativeDevSplitBundleLoaderModule.NAME)
|
||||
public class NativeDevSplitBundleLoaderModule extends NativeDevSplitBundleLoaderSpec {
|
||||
public static final String NAME = "DevSplitBundleLoader";
|
||||
private static final String REJECTION_CODE = "E_BUNDLE_LOAD_ERROR";
|
||||
|
||||
private final DevSupportManager mDevSupportManager;
|
||||
|
||||
public NativeDevSplitBundleLoaderModule(
|
||||
ReactApplicationContext reactContext, DevSupportManager devSupportManager) {
|
||||
super(reactContext);
|
||||
mDevSupportManager = devSupportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBundle(String bundlePath, final Promise promise) {
|
||||
mDevSupportManager.loadSplitBundleFromServer(
|
||||
bundlePath,
|
||||
new DevSplitBundleCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
promise.resolve(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String url, Throwable cause) {
|
||||
String message =
|
||||
cause instanceof DebugServerException
|
||||
? ((DebugServerException) cause).getOriginalMessage()
|
||||
: "Unknown error fetching '" + url + "'.";
|
||||
promise.reject(REJECTION_CODE, message, cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user