expose JS source location to JS

Differential Revision: D2526103

fb-gh-sync-id: d597b52dd9442fc27b0841b7df447e9d8d7de6e1
This commit is contained in:
Felix Oghină 2015-10-09 04:22:51 -07:00 коммит произвёл facebook-github-bot-9
Родитель fffae394c7
Коммит 3a0a1a4122
3 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -60,7 +60,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager()),
new Timing(catalystApplicationContext),
new SourceCodeModule(
mReactInstanceManager.getDevSupportManager().getSourceUrl(),
mReactInstanceManager.getSourceUrl(),
mReactInstanceManager.getDevSupportManager().getSourceMapUrl()),
new UIManagerModule(
catalystApplicationContext,

Просмотреть файл

@ -86,6 +86,7 @@ public class ReactInstanceManager {
private @Nullable volatile ReactContext mCurrentReactContext;
private final Context mApplicationContext;
private @Nullable DefaultHardwareBackBtnHandler mDefaultBackButtonImpl;
private String mSourceUrl;
private final ReactInstanceDevCommandsHandler mDevInterface =
new ReactInstanceDevCommandsHandler() {
@ -340,6 +341,13 @@ public class ReactInstanceManager {
mDevSupportManager.showDevOptionsDialog();
}
/**
* Get the URL where the last bundle was loaded from.
*/
public String getSourceUrl() {
return Assertions.assertNotNull(mSourceUrl);
}
/**
* Attach given {@param rootView} to a catalyst instance manager and start JS application using
* JS module provided by {@link ReactRootView#getJSModuleName}. If the react context is currently
@ -493,6 +501,7 @@ public class ReactInstanceManager {
JavaScriptExecutor jsExecutor,
JSBundleLoader jsBundleLoader) {
FLog.i(ReactConstants.TAG, "Creating react context.");
mSourceUrl = jsBundleLoader.getSourceUrl();
NativeModuleRegistry.Builder nativeRegistryBuilder = new NativeModuleRegistry.Builder();
JavaScriptModulesConfig.Builder jsModulesBuilder = new JavaScriptModulesConfig.Builder();

Просмотреть файл

@ -30,6 +30,11 @@ public abstract class JSBundleLoader {
public void loadScript(ReactBridge bridge) {
bridge.loadScriptFromAssets(assetManager, assetFileName);
}
@Override
public String getSourceUrl() {
return "file:///android_asset/" + assetFileName;
}
};
}
@ -48,6 +53,11 @@ public abstract class JSBundleLoader {
public void loadScript(ReactBridge bridge) {
bridge.loadScriptFromNetworkCached(sourceURL, cachedFileLocation);
}
@Override
public String getSourceUrl() {
return sourceURL;
}
};
}
@ -62,8 +72,14 @@ public abstract class JSBundleLoader {
public void loadScript(ReactBridge bridge) {
bridge.loadScriptFromNetworkCached(sourceURL, null);
}
@Override
public String getSourceUrl() {
return sourceURL;
}
};
}
public abstract void loadScript(ReactBridge bridge);
public abstract String getSourceUrl();
}