Prevent class loading for lazy native modules

Summary:
When native modules use `LazyReactPackage`, the modules themselves are not initialized. However, they still use the class names, causing the classes to load. This diff removes the need to perform any class loads. Any properties of the classes that are required are now populated in the `ReactModuleInfo` of that class.

Note that this diff itself does not prevent class loading since any references to `*.class` in `LazyReactpackage` needs to be removed in a consequent diff

Reviewed By: achen1

Differential Revision: D8950025

fbshipit-source-id: 80ddf7e1f33bf2af0db1bd262069795de77ec611
This commit is contained in:
Ram N
2018-07-27 23:30:39 -07:00
committed by Facebook Github Bot
parent d891ee1dee
commit c8e000b19a
9 changed files with 94 additions and 44 deletions

View File

@@ -40,6 +40,8 @@ public class ModuleHolder {
private final String mName;
private final boolean mCanOverrideExistingModule;
private final boolean mHasConstants;
private final boolean mIsCxxModule;
private final boolean mHasOnBatchCompleteListener;
private @Nullable Provider<? extends NativeModule> mProvider;
// Outside of the constructur, these should only be checked or set when synchronized on this
@@ -55,6 +57,8 @@ public class ModuleHolder {
mCanOverrideExistingModule = moduleInfo.canOverrideExistingModule();
mHasConstants = moduleInfo.hasConstants();
mProvider = provider;
mHasOnBatchCompleteListener = moduleInfo.hasOnBatchCompleteListener();
mIsCxxModule = moduleInfo.isCxxModule();
if (moduleInfo.needsEagerInit()) {
mModule = create();
}
@@ -64,6 +68,8 @@ public class ModuleHolder {
mName = nativeModule.getName();
mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
mHasConstants = true;
mIsCxxModule = CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass());
mHasOnBatchCompleteListener = OnBatchCompleteListener.class.isAssignableFrom(nativeModule.getClass());
mModule = nativeModule;
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
@@ -113,6 +119,10 @@ public class ModuleHolder {
return mHasConstants;
}
public boolean isCxxModule() {return mIsCxxModule; }
public boolean hasOnBatchCompleteListener() {return mHasOnBatchCompleteListener; }
@DoNotStrip
public NativeModule getModule() {
NativeModule module;