From a3a5a600520dff7dc9504ec290fc7936c4afd3e7 Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Tue, 9 Apr 2024 07:17:24 -0700 Subject: [PATCH] //xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations:annotationsAndroid (#43937) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43937 Changelog: [Internal] Reviewed By: cortinico Differential Revision: D55724728 fbshipit-source-id: 8536aa8eb1c8876fa1208932f5c706ef239d4212 --- .../react/module/annotations/ReactModule.java | 53 ------------------- .../react/module/annotations/ReactModule.kt | 42 +++++++++++++++ .../module/annotations/ReactModuleList.java | 31 ----------- .../module/annotations/ReactModuleList.kt | 26 +++++++++ 4 files changed, 68 insertions(+), 84 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java deleted file mode 100644 index ff9fa926745..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java +++ /dev/null @@ -1,53 +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.annotations; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Annotation for use on {@link com.facebook.react.bridge.BaseJavaModule}s to describe properties - * for that module. - */ -@Retention(RUNTIME) -@Target(TYPE) -public @interface ReactModule { - /** Name used to {@code require()} this module from JavaScript. */ - String name(); - - /** - * True if you intend to override some other native module that was registered e.g. as part of a - * different package (such as the core one). Trying to override without returning true from this - * method is considered an error and will throw an exception during initialization. By default all - * modules return false. - */ - boolean canOverrideExistingModule() default false; - - /** Whether this module needs to be loaded immediately. */ - boolean needsEagerInit() default false; - - /** - * Whether this module has constants to add, defaults to true as that is safer for when a correct - * annotation is not included - * - * @deprecated This property is unused and it's planning to be removed in a future version of - * React Native. Please refrain from using it. - */ - @Deprecated - boolean hasConstants() default true; - - /** - * Indicates if a module is a C++ module or a Java Module - * - * @return - */ - boolean isCxxModule() default false; -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.kt new file mode 100644 index 00000000000..0e021920059 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.kt @@ -0,0 +1,42 @@ +/* + * 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.annotations + +/** + * Annotation for use on [com.facebook.react.bridge.BaseJavaModule]s to describe properties for that + * module. + */ +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.CLASS) +public annotation class ReactModule( + /** Name used to `require()` this module from JavaScript. */ + public val name: String, + /** + * True if you intend to override some other native module that was registered e.g. as part of a + * different package (such as the core one). Trying to override without returning true from this + * method is considered an error and will throw an exception during initialization. By default + * all modules return false. + */ + public val canOverrideExistingModule: Boolean = false, + /** Whether this module needs to be loaded immediately. */ + public val needsEagerInit: Boolean = false, + /** + * Whether this module has constants to add, defaults to true as that is safer for when a + * correct annotation is not included + */ + @get:Deprecated( + """This property is unused and it's planning to be removed in a future version of + React Native. Please refrain from using it.""") + public val hasConstants: Boolean = true, + /** + * Indicates if a module is a C++ module or a Java Module + * + * @return + */ + public val isCxxModule: Boolean = false +) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java deleted file mode 100644 index 7bfcdaf4031..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.java +++ /dev/null @@ -1,31 +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.annotations; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.SOURCE; - -import com.facebook.react.bridge.NativeModule; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Annotates a function that returns a list of ModuleSpecs from which we get a list of NativeModules - * to create ReactModuleInfos from. - */ -@Retention(SOURCE) -@Target(TYPE) -public @interface ReactModuleList { - - /** - * The Native modules in this list should be annotated with {@link ReactModule}. - * - * @return List of Native modules in the package. - */ - Class[] nativeModules(); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.kt new file mode 100644 index 00000000000..1508b8eef64 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModuleList.kt @@ -0,0 +1,26 @@ +/* + * 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.annotations + +import com.facebook.react.bridge.NativeModule +import kotlin.reflect.KClass + +/** + * Annotates a function that returns a list of ModuleSpecs from which we get a list of NativeModules + * to create ReactModuleInfos from. + */ +@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.CLASS) +public annotation class ReactModuleList( + /** + * The Native modules in this list should be annotated with [ReactModule]. + * + * @return List of Native modules in the package. + */ + public val nativeModules: Array> +)