mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-07 13:05:18 +08:00
Add ability to lazy load Native Java Modules
Summary: Utilizes the build time annotation processor ReactModuleSpecProcessor that creates ReactModuleInfos for modules annotated with ReactModule and listed in the ReactModuleList annotation of LazyReactPackages. This way we don't have to instantiate the native modules to get the name, canOverrideExistingModule, and supportsWebWorkers values of the native modules. In the NativeModuleRegistry, we either store these ReactModuleInfos inside of a ModuleHolder or if we can't get the ReactModuleInfo for a specific module we instantiate that module to get the values (as we previously did) to store in a LegacyModuleInfo. Reviewed By: astreet Differential Revision: D3796561 fbshipit-source-id: f8fb9b4993f59b51ce595eb2f2c3425129b28ce5
This commit is contained in:
committed by
Facebook Github Bot 3
parent
1f9b765f81
commit
797ca6c219
@@ -49,23 +49,23 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
}
|
||||
|
||||
private final CatalystInstance mCatalystInstance;
|
||||
private final BaseJavaModule mModule;
|
||||
private final ModuleHolder mModuleHolder;
|
||||
private final ArrayList<BaseJavaModule.JavaMethod> mMethods;
|
||||
|
||||
public JavaModuleWrapper(CatalystInstance catalystinstance, BaseJavaModule module) {
|
||||
public JavaModuleWrapper(CatalystInstance catalystinstance, ModuleHolder moduleHolder) {
|
||||
mCatalystInstance = catalystinstance;
|
||||
mModule = module;
|
||||
mMethods = new ArrayList<BaseJavaModule.JavaMethod>();
|
||||
mModuleHolder = moduleHolder;
|
||||
mMethods = new ArrayList<>();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public BaseJavaModule getModule() {
|
||||
return mModule;
|
||||
return (BaseJavaModule) mModuleHolder.getModule();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public String getName() {
|
||||
return mModule.getName();
|
||||
return mModuleHolder.getInfo().name();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@@ -73,7 +73,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
ArrayList<MethodDescriptor> descs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, BaseJavaModule.NativeMethod> entry :
|
||||
mModule.getMethods().entrySet()) {
|
||||
getModule().getMethods().entrySet()) {
|
||||
MethodDescriptor md = new MethodDescriptor();
|
||||
md.name = entry.getKey();
|
||||
md.type = entry.getValue().getType();
|
||||
@@ -92,7 +92,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
ArrayList<MethodDescriptor> descs = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, BaseJavaModule.NativeMethod> entry :
|
||||
mModule.getMethods().entrySet()) {
|
||||
getModule().getMethods().entrySet()) {
|
||||
MethodDescriptor md = new MethodDescriptor();
|
||||
md.name = entry.getKey();
|
||||
md.type = entry.getValue().getType();
|
||||
@@ -105,7 +105,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, BaseJavaModule.SyncNativeHook> entry :
|
||||
mModule.getSyncHooks().entrySet()) {
|
||||
getModule().getSyncHooks().entrySet()) {
|
||||
MethodDescriptor md = new MethodDescriptor();
|
||||
md.name = entry.getKey();
|
||||
md.type = BaseJavaModule.METHOD_TYPE_SYNC;
|
||||
@@ -127,7 +127,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants")
|
||||
.arg("moduleName", getName())
|
||||
.flush();
|
||||
Map<String, Object> map = mModule.getConstants();
|
||||
Map<String, Object> map = getModule().getConstants();
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants")
|
||||
@@ -146,7 +146,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
@DoNotStrip
|
||||
public boolean supportsWebWorkers() {
|
||||
return mModule.supportsWebWorkers();
|
||||
return getModule().supportsWebWorkers();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
|
||||
Reference in New Issue
Block a user