diff --git a/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java index 76ca0f00c..4055ec671 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java @@ -14,7 +14,6 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.OnBatchCompleteListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.common.ReactConstants; -import com.facebook.react.cxxbridge.LegacyModuleInfo; import com.facebook.react.cxxbridge.ModuleHolder; import com.facebook.react.cxxbridge.NativeModuleRegistry; import com.facebook.react.module.model.ReactModuleInfo; @@ -58,17 +57,20 @@ public class NativeModuleRegistryBuilder { throw new IllegalStateException("Native Java module " + type.getSimpleName() + " should be annotated with @ReactModule and added to a @ReactModuleList."); } - NativeModule nativeModule = moduleSpec.getProvider().get(); - LegacyModuleInfo legacyModuleInfo = new LegacyModuleInfo(type, nativeModule); - moduleHolder = new ModuleHolder(legacyModuleInfo, nativeModule); + moduleHolder = new ModuleHolder(moduleSpec.getProvider().get()); } else { - moduleHolder = new ModuleHolder(reactModuleInfo, moduleSpec.getProvider()); + moduleHolder = new ModuleHolder( + reactModuleInfo.name(), + reactModuleInfo.canOverrideExistingModule(), + reactModuleInfo.supportsWebWorkers(), + reactModuleInfo.needsEagerInit(), + moduleSpec.getProvider()); } - String name = moduleHolder.getInfo().name(); + String name = moduleHolder.getName(); if (namesToType.containsKey(name)) { Class existingNativeModule = namesToType.get(name); - if (!moduleHolder.getInfo().canOverrideExistingModule()) { + if (!moduleHolder.getCanOverrideExistingModule()) { throw new IllegalStateException("Native module " + type.getSimpleName() + " tried to override " + existingNativeModule.getSimpleName() + " for module name " + name + ". If this was your intention, set canOverrideExistingModule=true"); @@ -106,8 +108,7 @@ public class NativeModuleRegistryBuilder { } namesToType.put(name, type); - LegacyModuleInfo legacyModuleInfo = new LegacyModuleInfo(type, nativeModule); - ModuleHolder moduleHolder = new ModuleHolder(legacyModuleInfo, nativeModule); + ModuleHolder moduleHolder = new ModuleHolder(nativeModule); mModules.put(type, moduleHolder); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaModuleWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaModuleWrapper.java index 45c197c5f..0c549ba66 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaModuleWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaModuleWrapper.java @@ -67,7 +67,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; @DoNotStrip public String getName() { - return mModuleHolder.getInfo().name(); + return mModuleHolder.getName(); } @DoNotStrip diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/LegacyModuleInfo.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/LegacyModuleInfo.java deleted file mode 100644 index 01457572c..000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/LegacyModuleInfo.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -package com.facebook.react.cxxbridge; - -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.module.model.Info; - -/** - * Module info for non-lazy native modules. - */ -public class LegacyModuleInfo implements Info { - - public final Class mType; - public final NativeModule mNativeModule; - - public LegacyModuleInfo(Class type, NativeModule nativeModule) { - mType = type; - mNativeModule = nativeModule; - } - - @Override - public String name() { - return mNativeModule.getName(); - } - - @Override - public boolean canOverrideExistingModule() { - return mNativeModule.canOverrideExistingModule(); - } - - @Override - public boolean supportsWebWorkers() { - return mNativeModule.supportsWebWorkers(); - } - - @Override - public boolean needsEagerInit() { - return true; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ModuleHolder.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ModuleHolder.java index 4daf267af..449fbcf3b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ModuleHolder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ModuleHolder.java @@ -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 mProvider; private @Nullable NativeModule mModule; private boolean mInitializeNeeded; - public ModuleHolder(ReactModuleInfo info, Provider provider) { - mInfo = info; + public ModuleHolder( + String name, + boolean canOverrideExistingModule, + boolean supportsWebWorkers, + boolean needsEagerInit, + Provider 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); diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/Info.java b/ReactAndroid/src/main/java/com/facebook/react/module/model/Info.java deleted file mode 100644 index c280b8833..000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/module/model/Info.java +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -package com.facebook.react.module.model; - -/** - * Interface for static information about native modules. - */ -public interface Info { - - String name(); - - boolean canOverrideExistingModule(); - - boolean supportsWebWorkers(); - - boolean needsEagerInit(); -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java b/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java index bb3328bac..93093531c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java +++ b/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java @@ -6,7 +6,7 @@ package com.facebook.react.module.model; * Data holder class holding native module specifications. {@link ReactModuleSpecProcessor} creates * these so Java modules don't have to be instantiated at React Native start up. */ -public class ReactModuleInfo implements Info { +public class ReactModuleInfo { private final String mName; private final boolean mCanOverrideExistingModule; @@ -24,22 +24,18 @@ public class ReactModuleInfo implements Info { mNeedsEagerInit = needsEagerInit; } - @Override public String name() { return mName; } - @Override public boolean canOverrideExistingModule() { return mCanOverrideExistingModule; } - @Override public boolean supportsWebWorkers() { return mSupportsWebWorkers; } - @Override public boolean needsEagerInit() { return mNeedsEagerInit; }