mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Adopt split segments registration approach on Android
Differential Revision: D6284863 fbshipit-source-id: 0df6b90eb0cbeab4c8a2b11f1e4dcbd5d5dfab72
This commit is contained in:
committed by
Facebook Github Bot
parent
681278947e
commit
a47431ed74
@@ -86,6 +86,9 @@ public interface CatalystInstance
|
|||||||
*/
|
*/
|
||||||
void removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener);
|
void removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener);
|
||||||
|
|
||||||
|
/** This method registers the file path of an additional JS segment by its ID. */
|
||||||
|
void registerSegment(int segmentId, String path);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setGlobalVariable(String propName, String jsonValue);
|
void setGlobalVariable(String propName, String jsonValue);
|
||||||
|
|
||||||
|
|||||||
@@ -210,8 +210,9 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
jniSetSourceURL(remoteURL);
|
jniSetSourceURL(remoteURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void setJsSegmentsDirectory(String directoryPath) {
|
@Override
|
||||||
jniSetJsSegmentsDirectory(directoryPath);
|
public void registerSegment(int segmentId, String path) {
|
||||||
|
jniRegisterSegment(segmentId, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void loadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously) {
|
/* package */ void loadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously) {
|
||||||
@@ -225,7 +226,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private native void jniSetSourceURL(String sourceURL);
|
private native void jniSetSourceURL(String sourceURL);
|
||||||
private native void jniSetJsSegmentsDirectory(String directoryPath);
|
private native void jniRegisterSegment(int segmentId, String path);
|
||||||
private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously);
|
private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously);
|
||||||
private native void jniLoadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously);
|
private native void jniLoadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously);
|
||||||
|
|
||||||
|
|||||||
@@ -96,21 +96,6 @@ public abstract class JSBundleLoader {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This loader is used to wrap other loaders and set js segments directory before executing
|
|
||||||
* application script.
|
|
||||||
*/
|
|
||||||
public static JSBundleLoader createSplitBundlesLoader(
|
|
||||||
final String jsSegmentsDirectory, final JSBundleLoader delegate) {
|
|
||||||
return new JSBundleLoader() {
|
|
||||||
@Override
|
|
||||||
public String loadScript(CatalystInstanceImpl instance) {
|
|
||||||
instance.setJsSegmentsDirectory(jsSegmentsDirectory);
|
|
||||||
return delegate.loadScript(instance);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Loads the script, returning the URL of the source it loaded. */
|
/** Loads the script, returning the URL of the source it loaded. */
|
||||||
public abstract String loadScript(CatalystInstanceImpl instance);
|
public abstract String loadScript(CatalystInstanceImpl instance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ void CatalystInstanceImpl::registerNatives() {
|
|||||||
makeNativeMethod("initializeBridge", CatalystInstanceImpl::initializeBridge),
|
makeNativeMethod("initializeBridge", CatalystInstanceImpl::initializeBridge),
|
||||||
makeNativeMethod("jniExtendNativeModules", CatalystInstanceImpl::extendNativeModules),
|
makeNativeMethod("jniExtendNativeModules", CatalystInstanceImpl::extendNativeModules),
|
||||||
makeNativeMethod("jniSetSourceURL", CatalystInstanceImpl::jniSetSourceURL),
|
makeNativeMethod("jniSetSourceURL", CatalystInstanceImpl::jniSetSourceURL),
|
||||||
makeNativeMethod("jniSetJsSegmentsDirectory", CatalystInstanceImpl::jniSetJsSegmentsDirectory),
|
makeNativeMethod("jniRegisterSegment", CatalystInstanceImpl::jniRegisterSegment),
|
||||||
makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets),
|
makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets),
|
||||||
makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile),
|
makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile),
|
||||||
makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction),
|
makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction),
|
||||||
@@ -177,8 +177,8 @@ void CatalystInstanceImpl::jniSetSourceURL(const std::string& sourceURL) {
|
|||||||
instance_->setSourceURL(sourceURL);
|
instance_->setSourceURL(sourceURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CatalystInstanceImpl::jniSetJsSegmentsDirectory(const std::string& directoryPath) {
|
void CatalystInstanceImpl::jniRegisterSegment(int segmentId, const std::string& path) {
|
||||||
jsSegmentsDirectory_ = directoryPath;
|
instance_->registerBundle((uint32_t)segmentId, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CatalystInstanceImpl::jniLoadScriptFromAssets(
|
void CatalystInstanceImpl::jniLoadScriptFromAssets(
|
||||||
@@ -208,16 +208,7 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
|
|||||||
const std::string& sourceURL,
|
const std::string& sourceURL,
|
||||||
bool loadSynchronously) {
|
bool loadSynchronously) {
|
||||||
if (Instance::isIndexedRAMBundle(fileName.c_str())) {
|
if (Instance::isIndexedRAMBundle(fileName.c_str())) {
|
||||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(fileName.c_str());
|
instance_->loadRAMBundleFromFile(fileName, sourceURL, loadSynchronously);
|
||||||
auto script = bundle->getStartupCode();
|
|
||||||
auto registry = jsSegmentsDirectory_.empty()
|
|
||||||
? RAMBundleRegistry::singleBundleRegistry(std::move(bundle))
|
|
||||||
: RAMBundleRegistry::multipleBundlesRegistry(std::move(bundle), JSIndexedRAMBundle::buildFactory());
|
|
||||||
instance_->loadRAMBundle(
|
|
||||||
std::move(registry),
|
|
||||||
std::move(script),
|
|
||||||
sourceURL,
|
|
||||||
loadSynchronously);
|
|
||||||
} else {
|
} else {
|
||||||
std::unique_ptr<const JSBigFileString> script;
|
std::unique_ptr<const JSBigFileString> script;
|
||||||
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
|
|||||||
void jniSetSourceURL(const std::string& sourceURL);
|
void jniSetSourceURL(const std::string& sourceURL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the path to folder where additional bundles are located.
|
* Registers the file path of an additional JS segment by its ID.
|
||||||
* Needs to be invoked before "loadScript" methods are called.
|
*
|
||||||
*/
|
*/
|
||||||
void jniSetJsSegmentsDirectory(const std::string& directoryPath);
|
void jniRegisterSegment(int segmentId, const std::string& path);
|
||||||
|
|
||||||
void jniLoadScriptFromAssets(jni::alias_ref<JAssetManager::javaobject> assetManager, const std::string& assetURL, bool loadSynchronously);
|
void jniLoadScriptFromAssets(jni::alias_ref<JAssetManager::javaobject> assetManager, const std::string& assetURL, bool loadSynchronously);
|
||||||
void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL, bool loadSynchronously);
|
void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL, bool loadSynchronously);
|
||||||
@@ -74,8 +74,6 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
|
|||||||
jlong getJavaScriptContext();
|
jlong getJavaScriptContext();
|
||||||
void handleMemoryPressure(int pressureLevel);
|
void handleMemoryPressure(int pressureLevel);
|
||||||
|
|
||||||
std::string jsSegmentsDirectory_;
|
|
||||||
|
|
||||||
// This should be the only long-lived strong reference, but every C++ class
|
// This should be the only long-lived strong reference, but every C++ class
|
||||||
// will have a weak reference.
|
// will have a weak reference.
|
||||||
std::shared_ptr<Instance> instance_;
|
std::shared_ptr<Instance> instance_;
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ void Instance::loadRAMBundleFromFile(const std::string& sourcePath,
|
|||||||
bool loadSynchronously) {
|
bool loadSynchronously) {
|
||||||
auto bundle = folly::make_unique<JSIndexedRAMBundle>(sourcePath.c_str());
|
auto bundle = folly::make_unique<JSIndexedRAMBundle>(sourcePath.c_str());
|
||||||
auto startupScript = bundle->getStartupCode();
|
auto startupScript = bundle->getStartupCode();
|
||||||
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
|
auto registry = RAMBundleRegistry::multipleBundlesRegistry(std::move(bundle), JSIndexedRAMBundle::buildFactory());
|
||||||
loadRAMBundle(
|
loadRAMBundle(
|
||||||
std::move(registry),
|
std::move(registry),
|
||||||
std::move(startupScript),
|
std::move(startupScript),
|
||||||
|
|||||||
Reference in New Issue
Block a user