mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
merge module info into ModuleHolder
Reviewed By: javache Differential Revision: D4512982 fbshipit-source-id: e1272812f95d08f2c3eb834a18da842d425b3edb
This commit is contained in:
1 parent
7555ae13d1
commit
9f3e928f83
6 files changed
+43
-86
No files matched your search
@@ -10,8 +10,6 @@ import java.util.concurrent.ExecutionException;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactMarker;
|
||||
import com.facebook.react.common.futures.SimpleSettableFuture;
|
||||
import com.facebook.react.module.model.Info;
|
||||
import com.facebook.react.module.model.ReactModuleInfo;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
@@ -31,21 +29,33 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
*/
|
||||
public class ModuleHolder {
|
||||
|
||||
private final Info mInfo;
|
||||
private final String mName;
|
||||
private final boolean mCanOverrideExistingModule;
|
||||
private final boolean mSupportsWebWorkers;
|
||||
|
||||
private @Nullable Provider<? extends NativeModule> mProvider;
|
||||
private @Nullable NativeModule mModule;
|
||||
private boolean mInitializeNeeded;
|
||||
|
||||
public ModuleHolder(ReactModuleInfo info, Provider<? extends NativeModule> provider) {
|
||||
mInfo = info;
|
||||
public ModuleHolder(
|
||||
String name,
|
||||
boolean canOverrideExistingModule,
|
||||
boolean supportsWebWorkers,
|
||||
boolean needsEagerInit,
|
||||
Provider<? extends NativeModule> provider) {
|
||||
mName = name;
|
||||
mCanOverrideExistingModule = canOverrideExistingModule;
|
||||
mSupportsWebWorkers = supportsWebWorkers;
|
||||
mProvider = provider;
|
||||
if (mInfo.needsEagerInit()) {
|
||||
if (needsEagerInit) {
|
||||
mModule = doCreate();
|
||||
}
|
||||
}
|
||||
|
||||
public ModuleHolder(LegacyModuleInfo info, NativeModule nativeModule) {
|
||||
mInfo = info;
|
||||
public ModuleHolder(NativeModule nativeModule) {
|
||||
mName = nativeModule.getName();
|
||||
mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
|
||||
mSupportsWebWorkers = nativeModule.supportsWebWorkers();
|
||||
mModule = nativeModule;
|
||||
}
|
||||
|
||||
@@ -63,8 +73,16 @@ public class ModuleHolder {
|
||||
}
|
||||
}
|
||||
|
||||
public Info getInfo() {
|
||||
return mInfo;
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public boolean getCanOverrideExistingModule() {
|
||||
return mCanOverrideExistingModule;
|
||||
}
|
||||
|
||||
public boolean getSupportsWebWorkers() {
|
||||
return mSupportsWebWorkers;
|
||||
}
|
||||
|
||||
public synchronized NativeModule getModule() {
|
||||
@@ -81,13 +99,12 @@ public class ModuleHolder {
|
||||
}
|
||||
|
||||
private NativeModule create() {
|
||||
boolean isEagerModule = mInfo instanceof LegacyModuleInfo;
|
||||
String name = isEagerModule ? ((LegacyModuleInfo) mInfo).mType.getSimpleName() : mInfo.name();
|
||||
boolean isEagerModule = mModule != null;
|
||||
if (!isEagerModule) {
|
||||
ReactMarker.logMarker(CREATE_MODULE_START);
|
||||
}
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createModule")
|
||||
.arg("name", name)
|
||||
.arg("name", mName)
|
||||
.flush();
|
||||
NativeModule module = assertNotNull(mProvider).get();
|
||||
if (mInitializeNeeded) {
|
||||
@@ -107,7 +124,7 @@ public class ModuleHolder {
|
||||
if (module instanceof CxxModuleWrapper) {
|
||||
section.arg("className", module.getClass().getSimpleName());
|
||||
} else {
|
||||
section.arg("name", mInfo.name());
|
||||
section.arg("name", mName);
|
||||
}
|
||||
section.flush();
|
||||
callInitializeOnUiThread(module);
|
||||
|
||||
Reference in new issue
Block a user