mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 09:29:07 +08:00
stash the Source URL when loading a script.
Reviewed By: javache Differential Revision: D4437195 fbshipit-source-id: 14698fc81bbe24cab81668bfb54578fc434abc58
This commit is contained in:
committed by
Facebook Github Bot
parent
cec787563a
commit
2ade5f3781
@@ -181,10 +181,40 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
MessageQueueThread moduleQueue,
|
||||
ModuleRegistryHolder registryHolder);
|
||||
|
||||
/* package */ native void setSourceURL(String sourceURL);
|
||||
/* package */ native void loadScriptFromAssets(AssetManager assetManager, String assetURL);
|
||||
/* package */ native void loadScriptFromFile(String fileName, String sourceURL);
|
||||
/* package */ native void loadScriptFromOptimizedBundle(String path, String sourceURL, int flags);
|
||||
/**
|
||||
* This API is used in situations where the JS bundle is being executed not on
|
||||
* the device, but on a host machine. In that case, we must provide two source
|
||||
* URLs for the JS bundle: One to be used on the device, and one to be used on
|
||||
* the remote debugging machine.
|
||||
*
|
||||
* @param deviceURL A source URL that is accessible from this device.
|
||||
* @param remoteURL A source URL that is accessible from the remote machine
|
||||
* executing the JS.
|
||||
*/
|
||||
/* package */ void setSourceURLs(String deviceURL, String remoteURL) {
|
||||
mSourceURL = deviceURL;
|
||||
jniSetSourceURL(remoteURL);
|
||||
}
|
||||
|
||||
/* package */ void loadScriptFromAssets(AssetManager assetManager, String assetURL) {
|
||||
mSourceURL = assetURL;
|
||||
jniLoadScriptFromAssets(assetManager, assetURL);
|
||||
}
|
||||
|
||||
/* package */ void loadScriptFromFile(String fileName, String sourceURL) {
|
||||
mSourceURL = sourceURL;
|
||||
jniLoadScriptFromFile(fileName, sourceURL);
|
||||
}
|
||||
|
||||
/* package */ void loadScriptFromOptimizedBundle(String path, String sourceURL, int flags) {
|
||||
mSourceURL = sourceURL;
|
||||
jniLoadScriptFromOptimizedBundle(path, sourceURL, flags);
|
||||
}
|
||||
|
||||
private native void jniSetSourceURL(String sourceURL);
|
||||
private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL);
|
||||
private native void jniLoadScriptFromFile(String fileName, String sourceURL);
|
||||
private native void jniLoadScriptFromOptimizedBundle(String path, String sourceURL, int flags);
|
||||
|
||||
@Override
|
||||
public void runJSBundle() {
|
||||
@@ -192,7 +222,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
mJSBundleHasLoaded = true;
|
||||
|
||||
// incrementPendingJSCalls();
|
||||
mSourceURL = mJSBundleLoader.loadScript(CatalystInstanceImpl.this);
|
||||
mJSBundleLoader.loadScript(CatalystInstanceImpl.this);
|
||||
|
||||
synchronized (mJSCallsPendingInitLock) {
|
||||
// Loading the bundle is queued on the JS thread, but may not have
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class JSBundleLoader {
|
||||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public String loadScript(CatalystInstanceImpl instance) {
|
||||
instance.setSourceURL(proxySourceURL);
|
||||
instance.setSourceURLs(realSourceURL, proxySourceURL);
|
||||
return realSourceURL;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,22 +26,11 @@ import com.facebook.react.module.annotations.ReactModule;
|
||||
public class SourceCodeModule extends BaseJavaModule {
|
||||
|
||||
private final ReactContext mReactContext;
|
||||
private @Nullable String mSourceUrl;
|
||||
|
||||
public SourceCodeModule(ReactContext reactContext) {
|
||||
mReactContext = reactContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
mSourceUrl =
|
||||
Assertions.assertNotNull(
|
||||
mReactContext.getCatalystInstance().getSourceURL(),
|
||||
"No source URL loaded, have you initialised the instance?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RCTSourceCode";
|
||||
@@ -50,7 +39,13 @@ public class SourceCodeModule extends BaseJavaModule {
|
||||
@Override
|
||||
public @Nullable Map<String, Object> getConstants() {
|
||||
HashMap<String, Object> constants = new HashMap<>();
|
||||
constants.put("scriptURL", mSourceUrl);
|
||||
|
||||
String sourceURL =
|
||||
Assertions.assertNotNull(
|
||||
mReactContext.getCatalystInstance().getSourceURL(),
|
||||
"No source URL loaded, have you initialised the instance?");
|
||||
|
||||
constants.put("scriptURL", sourceURL);
|
||||
return constants;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user