diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index de9e205a7fc..2c8a203c4eb 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2954,17 +2954,22 @@ public abstract interface annotation class com/facebook/react/module/annotations public abstract fun nativeModules ()[Ljava/lang/Class; } -public class com/facebook/react/module/model/ReactModuleInfo { +public final class com/facebook/react/module/model/ReactModuleInfo { + public static final field Companion Lcom/facebook/react/module/model/ReactModuleInfo$Companion; public fun (Ljava/lang/String;Ljava/lang/String;ZZZZ)V public fun (Ljava/lang/String;Ljava/lang/String;ZZZZZ)V - public fun canOverrideExistingModule ()Z - public static fun classIsTurboModule (Ljava/lang/Class;)Z - public fun className ()Ljava/lang/String; - public fun hasConstants ()Z - public fun isCxxModule ()Z - public fun isTurboModule ()Z - public fun name ()Ljava/lang/String; - public fun needsEagerInit ()Z + public final fun canOverrideExistingModule ()Z + public static final fun classIsTurboModule (Ljava/lang/Class;)Z + public final fun className ()Ljava/lang/String; + public final fun hasConstants ()Z + public final fun isCxxModule ()Z + public final fun isTurboModule ()Z + public final fun name ()Ljava/lang/String; + public final fun needsEagerInit ()Z +} + +public final class com/facebook/react/module/model/ReactModuleInfo$Companion { + public final fun classIsTurboModule (Ljava/lang/Class;)Z } public abstract interface class com/facebook/react/module/model/ReactModuleInfoProvider { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java deleted file mode 100644 index 13405c1131b..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.module.model; - -import com.facebook.react.turbomodule.core.interfaces.TurboModule; - -/** - * 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 { - - private final String mName; - private final boolean mCanOverrideExistingModule; - private final boolean mNeedsEagerInit; - private final boolean mIsCxxModule; - private final String mClassName; - private final boolean mIsTurboModule; - - public ReactModuleInfo( - String name, - String className, - boolean canOverrideExistingModule, - boolean needsEagerInit, - boolean isCxxModule, - boolean isTurboModule) { - mName = name; - mClassName = className; - mCanOverrideExistingModule = canOverrideExistingModule; - mNeedsEagerInit = needsEagerInit; - mIsCxxModule = isCxxModule; - mIsTurboModule = isTurboModule; - } - - /** - * @deprecated use {@link ReactModuleInfo#ReactModuleInfo(String, String, boolean, boolean, - * boolean, boolean)} - */ - @Deprecated - public ReactModuleInfo( - String name, - String className, - boolean canOverrideExistingModule, - boolean needsEagerInit, - boolean hasConstants, - boolean isCxxModule, - boolean isTurboModule) { - this(name, className, canOverrideExistingModule, needsEagerInit, isCxxModule, isTurboModule); - } - - public String name() { - return mName; - } - - public String className() { - return mClassName; - } - - public boolean canOverrideExistingModule() { - return mCanOverrideExistingModule; - } - - public boolean needsEagerInit() { - return mNeedsEagerInit; - } - - /** - * @deprecated this is hardcoded to return true, regardless if the module has constants or not - */ - @Deprecated - public boolean hasConstants() { - return true; - } - - public boolean isCxxModule() { - return mIsCxxModule; - } - - public boolean isTurboModule() { - return mIsTurboModule; - } - - /** - * Checks if the passed class is a TurboModule. Useful to populate the parameter [isTurboModule] - * in the constructor of ReactModuleInfo. - */ - public static boolean classIsTurboModule(Class clazz) { - return TurboModule.class.isAssignableFrom(clazz); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.kt new file mode 100644 index 00000000000..7a62f312f40 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.kt @@ -0,0 +1,56 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.module.model + +import com.facebook.react.turbomodule.core.interfaces.TurboModule + +/** + * Data holder class holding native module specifications. [ReactModuleSpecProcessor] creates these + * so Java modules don't have to be instantiated at React Native start up. + */ +public class ReactModuleInfo( + private val _name: String, + private val _className: String, + private val _canOverrideExistingModule: Boolean, + private val _needsEagerInit: Boolean, + public val isCxxModule: Boolean, + public val isTurboModule: Boolean +) { + + @Deprecated("use ReactModuleInfo(String, String, boolean, boolean, boolean, boolean)]") + public constructor( + name: String, + className: String, + canOverrideExistingModule: Boolean, + needsEagerInit: Boolean, + @Suppress("UNUSED_PARAMETER") hasConstants: Boolean, + isCxxModule: Boolean, + isTurboModule: Boolean + ) : this(name, className, canOverrideExistingModule, needsEagerInit, isCxxModule, isTurboModule) + + public fun name(): String = _name + + public fun className(): String = _className + + public fun canOverrideExistingModule(): Boolean = _canOverrideExistingModule + + public fun needsEagerInit(): Boolean = _needsEagerInit + + @Deprecated("this is hardcoded to return true, regardless if the module has constants or not") + public fun hasConstants(): Boolean = true + + public companion object { + /** + * Checks if the passed class is a TurboModule. Useful to populate the parameter [isTurboModule] + * in the constructor of ReactModuleInfo. + */ + @JvmStatic + public fun classIsTurboModule(clazz: Class<*>): Boolean = + TurboModule::class.java.isAssignableFrom(clazz) + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.kt similarity index 62% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.kt index c430ec2c8fd..5bfcaa1bb6d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfoProvider.kt @@ -5,12 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.module.model; - -import java.util.Map; +package com.facebook.react.module.model /** Interface for auto-generated class by ReactModuleSpecProcessor. */ -public interface ReactModuleInfoProvider { - - Map getReactModuleInfos(); +public fun interface ReactModuleInfoProvider { + public fun getReactModuleInfos(): Map }