force crash if a Java Module isn't lazifi-able in a Lazified app
Reviewed By: achen1 Differential Revision: D4317878 fbshipit-source-id: 61ee4b24f0de206f53d6f4b3801d81aa6f3ab36c
This commit is contained in:
parent
8c7f36021a
commit
a76547f7ac
|
@ -80,7 +80,8 @@ public class ReactTestHelper {
|
|||
.setJSExecutor(executor)
|
||||
.setRegistry(new NativeModuleRegistry(
|
||||
mModuleSpecList,
|
||||
Collections.<Class, ReactModuleInfo>emptyMap()))
|
||||
Collections.<Class, ReactModuleInfo>emptyMap(),
|
||||
false))
|
||||
.setJSModuleRegistry(mJSModuleRegistryBuilder.build())
|
||||
.setJSBundleLoader(JSBundleLoader.createAssetLoader(
|
||||
mContext,
|
||||
|
|
|
@ -892,7 +892,10 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
|||
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
|
||||
NativeModuleRegistry nativeModuleRegistry;
|
||||
try {
|
||||
nativeModuleRegistry = new NativeModuleRegistry(moduleSpecs, reactModuleInfoMap);
|
||||
nativeModuleRegistry = new NativeModuleRegistry(
|
||||
moduleSpecs,
|
||||
reactModuleInfoMap,
|
||||
mLazyNativeModulesEnabled);
|
||||
} finally {
|
||||
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END);
|
||||
|
|
|
@ -36,14 +36,19 @@ public class NativeModuleRegistry {
|
|||
|
||||
public NativeModuleRegistry(
|
||||
List<ModuleSpec> moduleSpecList,
|
||||
Map<Class, ReactModuleInfo> reactModuleInfoMap) {
|
||||
Map<Class, ReactModuleInfo> reactModuleInfoMap,
|
||||
boolean isLazyNativeModulesEnabled) {
|
||||
Map<String, Pair<Class<? extends NativeModule>, ModuleHolder>> namesToSpecs = new HashMap<>();
|
||||
for (ModuleSpec module : moduleSpecList) {
|
||||
Class<? extends NativeModule> type = module.getType();
|
||||
ModuleHolder holder = new ModuleHolder(
|
||||
type,
|
||||
reactModuleInfoMap.get(type),
|
||||
module.getProvider());
|
||||
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type);
|
||||
if (isLazyNativeModulesEnabled &&
|
||||
reactModuleInfo == null &&
|
||||
BaseJavaModule.class.isAssignableFrom(type)) {
|
||||
throw new IllegalStateException("Native Java module " + type.getSimpleName() +
|
||||
" should be annotated with @ReactModule and added to a @ReactModuleList.");
|
||||
}
|
||||
ModuleHolder holder = new ModuleHolder(type, reactModuleInfo, module.getProvider());
|
||||
String name = holder.getInfo().name();
|
||||
Class<? extends NativeModule> existing = namesToSpecs.containsKey(name) ?
|
||||
namesToSpecs.get(name).first :
|
||||
|
|
Loading…
Reference in New Issue