mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-20 07:44:29 +08:00
CatalystInstanceImpl.setSourceURL
Reviewed By: javache Differential Revision: D4422416 fbshipit-source-id: bc49485ac64064909f32375b6b8360a0a505975b
This commit is contained in:
committed by
Facebook Github Bot
parent
bbd5750bb4
commit
76c4faee5e
@@ -181,6 +181,7 @@ 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);
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class JSBundleLoader {
|
||||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public String loadScript(CatalystInstanceImpl instance) {
|
||||
instance.loadScriptFromFile(null, proxySourceURL);
|
||||
instance.setSourceURL(proxySourceURL);
|
||||
return realSourceURL;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,8 +101,9 @@ CatalystInstanceImpl::CatalystInstanceImpl()
|
||||
|
||||
void CatalystInstanceImpl::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", CatalystInstanceImpl::initHybrid),
|
||||
makeNativeMethod("initHybrid", CatalystInstanceImpl::initHybrid),
|
||||
makeNativeMethod("initializeBridge", CatalystInstanceImpl::initializeBridge),
|
||||
makeNativeMethod("setSourceURL", CatalystInstanceImpl::setSourceURL),
|
||||
makeNativeMethod("loadScriptFromAssets",
|
||||
"(Landroid/content/res/AssetManager;Ljava/lang/String;)V",
|
||||
CatalystInstanceImpl::loadScriptFromAssets),
|
||||
@@ -158,6 +159,10 @@ void CatalystInstanceImpl::initializeBridge(
|
||||
mrh->getModuleRegistry());
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::setSourceURL(const std::string& sourceURL) {
|
||||
instance_->setSourceURL(sourceURL);
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::loadScriptFromAssets(jobject assetManager,
|
||||
const std::string& assetURL) {
|
||||
const int kAssetsLength = 9; // strlen("assets://");
|
||||
@@ -187,20 +192,18 @@ bool CatalystInstanceImpl::isIndexedRAMBundle(const char *sourcePath) {
|
||||
return parseTypeFromHeader(header) == ScriptTag::RAMBundle;
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::loadScriptFromFile(jni::alias_ref<jstring> fileName,
|
||||
void CatalystInstanceImpl::loadScriptFromFile(const std::string& fileName,
|
||||
const std::string& sourceURL) {
|
||||
|
||||
std::string file = fileName ? fileName->toStdString() : "";
|
||||
|
||||
if (isIndexedRAMBundle(file.c_str())) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(file.c_str());
|
||||
auto zFileName = fileName.c_str();
|
||||
if (isIndexedRAMBundle(zFileName)) {
|
||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(zFileName);
|
||||
auto startupScript = bundle->getStartupCode();
|
||||
instance_->loadUnbundle(
|
||||
std::move(bundle),
|
||||
std::move(startupScript),
|
||||
sourceURL);
|
||||
} else {
|
||||
instance_->loadScriptFromFile(file, sourceURL);
|
||||
instance_->loadScriptFromFile(fileName, sourceURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,14 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsQueue,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> moduleQueue,
|
||||
ModuleRegistryHolder* mrh);
|
||||
|
||||
/**
|
||||
* Sets the source URL of the underlying bridge without loading any JS code.
|
||||
*/
|
||||
void setSourceURL(const std::string& sourceURL);
|
||||
|
||||
void loadScriptFromAssets(jobject assetManager, const std::string& assetURL);
|
||||
void loadScriptFromFile(jni::alias_ref<jstring> fileName, const std::string& sourceURL);
|
||||
void loadScriptFromFile(const std::string& fileName, const std::string& sourceURL);
|
||||
void loadScriptFromOptimizedBundle(const std::string& bundlePath, const std::string& sourceURL, jint flags);
|
||||
void callJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments);
|
||||
void callJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments);
|
||||
|
||||
Reference in New Issue
Block a user