diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 340a04b69ec299..4b621781f44a7c 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -59,6 +59,7 @@ public abstract class com/facebook/react/HeadlessJsTaskService : android/app/Ser public final class com/facebook/react/JSEngineResolutionAlgorithm : java/lang/Enum { public static final field HERMES Lcom/facebook/react/JSEngineResolutionAlgorithm; public static final field JSC Lcom/facebook/react/JSEngineResolutionAlgorithm; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/JSEngineResolutionAlgorithm; public static fun values ()[Lcom/facebook/react/JSEngineResolutionAlgorithm; } @@ -926,6 +927,7 @@ public final class com/facebook/react/bridge/MemoryPressure : java/lang/Enum { public static final field CRITICAL Lcom/facebook/react/bridge/MemoryPressure; public static final field MODERATE Lcom/facebook/react/bridge/MemoryPressure; public static final field UI_HIDDEN Lcom/facebook/react/bridge/MemoryPressure; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/bridge/MemoryPressure; public static fun values ()[Lcom/facebook/react/bridge/MemoryPressure; } @@ -1431,6 +1433,7 @@ public final class com/facebook/react/bridge/ReadableType : java/lang/Enum { public static final field Null Lcom/facebook/react/bridge/ReadableType; public static final field Number Lcom/facebook/react/bridge/ReadableType; public static final field String Lcom/facebook/react/bridge/ReadableType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/bridge/ReadableType; public static fun values ()[Lcom/facebook/react/bridge/ReadableType; } @@ -1685,6 +1688,7 @@ public final class com/facebook/react/common/LifecycleState : java/lang/Enum { public static final field BEFORE_CREATE Lcom/facebook/react/common/LifecycleState; public static final field BEFORE_RESUME Lcom/facebook/react/common/LifecycleState; public static final field RESUMED Lcom/facebook/react/common/LifecycleState; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/common/LifecycleState; public static fun values ()[Lcom/facebook/react/common/LifecycleState; } @@ -1853,6 +1857,7 @@ public final class com/facebook/react/common/mapbuffer/MapBuffer$DataType : java public static final field LONG Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType; public static final field MAP Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType; public static final field STRING Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType; public static fun values ()[Lcom/facebook/react/common/mapbuffer/MapBuffer$DataType; } @@ -2426,6 +2431,7 @@ public final class com/facebook/react/devsupport/interfaces/ErrorType : java/lan public static final field JS Lcom/facebook/react/devsupport/interfaces/ErrorType; public static final field NATIVE Lcom/facebook/react/devsupport/interfaces/ErrorType; public final fun getDisplayName ()Ljava/lang/String; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public fun toString ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/devsupport/interfaces/ErrorType; public static fun values ()[Lcom/facebook/react/devsupport/interfaces/ErrorType; @@ -4211,6 +4217,7 @@ public final class com/facebook/react/uimanager/LengthPercentage$Companion { public final class com/facebook/react/uimanager/LengthPercentageType : java/lang/Enum { public static final field PERCENT Lcom/facebook/react/uimanager/LengthPercentageType; public static final field POINT Lcom/facebook/react/uimanager/LengthPercentageType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/LengthPercentageType; public static fun values ()[Lcom/facebook/react/uimanager/LengthPercentageType; } @@ -4264,6 +4271,7 @@ public final class com/facebook/react/uimanager/NativeKind : java/lang/Enum { public static final field LEAF Lcom/facebook/react/uimanager/NativeKind; public static final field NONE Lcom/facebook/react/uimanager/NativeKind; public static final field PARENT Lcom/facebook/react/uimanager/NativeKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/NativeKind; public static fun values ()[Lcom/facebook/react/uimanager/NativeKind; } @@ -4340,6 +4348,7 @@ public final class com/facebook/react/uimanager/PointerEvents : java/lang/Enum { public static final field NONE Lcom/facebook/react/uimanager/PointerEvents; public static final fun canBeTouchTarget (Lcom/facebook/react/uimanager/PointerEvents;)Z public static final fun canChildrenBeTouchTarget (Lcom/facebook/react/uimanager/PointerEvents;)Z + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static final fun parsePointerEvents (Ljava/lang/String;)Lcom/facebook/react/uimanager/PointerEvents; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/PointerEvents; public static fun values ()[Lcom/facebook/react/uimanager/PointerEvents; @@ -5788,6 +5797,7 @@ public final class com/facebook/react/uimanager/events/TouchEventType : java/lan public static final field END Lcom/facebook/react/uimanager/events/TouchEventType; public static final field MOVE Lcom/facebook/react/uimanager/events/TouchEventType; public static final field START Lcom/facebook/react/uimanager/events/TouchEventType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static final fun getJSEventName (Lcom/facebook/react/uimanager/events/TouchEventType;)Ljava/lang/String; public final fun getJsName ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/events/TouchEventType; @@ -5811,6 +5821,7 @@ public final class com/facebook/react/uimanager/layoutanimation/InterpolatorType public static final field LINEAR Lcom/facebook/react/uimanager/layoutanimation/InterpolatorType; public static final field SPRING Lcom/facebook/react/uimanager/layoutanimation/InterpolatorType; public static final fun fromString (Ljava/lang/String;)Lcom/facebook/react/uimanager/layoutanimation/InterpolatorType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/layoutanimation/InterpolatorType; public static fun values ()[Lcom/facebook/react/uimanager/layoutanimation/InterpolatorType; } @@ -5846,6 +5857,7 @@ public final class com/facebook/react/uimanager/style/BorderRadiusProp : java/la public static final field BORDER_TOP_LEFT_RADIUS Lcom/facebook/react/uimanager/style/BorderRadiusProp; public static final field BORDER_TOP_RIGHT_RADIUS Lcom/facebook/react/uimanager/style/BorderRadiusProp; public static final field BORDER_TOP_START_RADIUS Lcom/facebook/react/uimanager/style/BorderRadiusProp; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/style/BorderRadiusProp; public static fun values ()[Lcom/facebook/react/uimanager/style/BorderRadiusProp; } @@ -6309,6 +6321,7 @@ public final class com/facebook/react/views/image/ImageResizeMethod : java/lang/ public static final field AUTO Lcom/facebook/react/views/image/ImageResizeMethod; public static final field RESIZE Lcom/facebook/react/views/image/ImageResizeMethod; public static final field SCALE Lcom/facebook/react/views/image/ImageResizeMethod; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/views/image/ImageResizeMethod; public static fun values ()[Lcom/facebook/react/views/image/ImageResizeMethod; } @@ -7037,6 +7050,7 @@ public final class com/facebook/react/views/scroll/ScrollEventType : java/lang/E public static final field MOMENTUM_BEGIN Lcom/facebook/react/views/scroll/ScrollEventType; public static final field MOMENTUM_END Lcom/facebook/react/views/scroll/ScrollEventType; public static final field SCROLL Lcom/facebook/react/views/scroll/ScrollEventType; + public static fun getEntries ()Lkotlin/enums/EnumEntries; public static final fun getJSEventName (Lcom/facebook/react/views/scroll/ScrollEventType;)Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/views/scroll/ScrollEventType; public static fun values ()[Lcom/facebook/react/views/scroll/ScrollEventType; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.kt similarity index 78% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.kt index 495ea9d8067936..a714f92b7af944 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Callback.kt @@ -5,18 +5,16 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.bridge; - +package com.facebook.react.bridge /** * Interface that represent javascript callback function which can be passed to the native module as * a method parameter. */ -public interface Callback { - +public fun interface Callback { /** - * Schedule javascript function execution represented by this {@link Callback} instance + * Schedule javascript function execution represented by this [Callback] instance * * @param args arguments passed to javascript callback method via bridge */ - void invoke(Object... args); + public operator fun invoke(vararg args: Any?) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.kt similarity index 56% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.kt index e7e3d580b121eb..59f677997b1e5c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSExceptionHandler.kt @@ -5,19 +5,18 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.bridge; +package com.facebook.react.bridge /** * Interface for a class that knows how to handle an Exception invoked from JS. Since these * Exceptions are triggered by JS calls (and can be fixed in JS), a common way to handle one is to * show a error dialog and allow the developer to change and reload JS. * - *

We should also note that we have a unique stance on what 'caused' means: even if there's a bug - * in the framework/native code, it was triggered by JS and theoretically since we were able to set - * up the React Instance, JS could change its logic, reload, and not trigger that crash. + * We should also note that we have a unique stance on what 'caused' means: even if there's a bug in + * the framework/native code, it was triggered by JS and theoretically since we were able to set up + * the React Instance, JS could change its logic, reload, and not trigger that crash. */ -public interface JSExceptionHandler { - +public fun interface JSExceptionHandler { /** Do something to display or log the exception. */ - void handleException(Exception e); + public fun handleException(e: Exception) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.kt similarity index 66% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.kt index 9dd9972fe52c7f..4e86c116816223 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener.kt @@ -5,29 +5,26 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.bridge; - +package com.facebook.react.bridge /** * Interface for receiving notification for bridge idle/busy events. Should not affect application - * logic and should only be used for debug/monitoring/testing purposes. Call {@link - * CatalystInstance#addBridgeIdleDebugListener} to start monitoring. + * logic and should only be used for debug/monitoring/testing purposes. Call + * [ ][CatalystInstance.addBridgeIdleDebugListener] to start monitoring. * - *

NB: onTransitionToBridgeIdle and onTransitionToBridgeBusy may be called from different - * threads, and those threads may not be the same thread on which the listener was originally - * registered. + * NB: onTransitionToBridgeIdle and onTransitionToBridgeBusy may be called from different threads, + * and those threads may not be the same thread on which the listener was originally registered. */ public interface NotThreadSafeBridgeIdleDebugListener { - /** * Called once all pending JS calls have resolved via an onBatchComplete call in the bridge and * the requested native module calls have also run. The bridge will not become busy again until a * timer, touch event, etc. causes a Java->JS call to be enqueued again. */ - void onTransitionToBridgeIdle(); + public fun onTransitionToBridgeIdle() /** Called when the bridge was in an idle state and executes a JS call or callback. */ - void onTransitionToBridgeBusy(); + public fun onTransitionToBridgeBusy() /** Called when the bridge is destroyed */ - void onBridgeDestroyed(); + public fun onBridgeDestroyed() } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.kt similarity index 72% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.kt index 7808c782800738..b09e7c540f7ec6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/OnBatchCompleteListener.kt @@ -5,10 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.bridge; +package com.facebook.react.bridge /** Interface for a module that will be notified when a batch of JS->Java calls has finished. */ -public interface OnBatchCompleteListener { - - void onBatchComplete(); +public fun interface OnBatchCompleteListener { + public fun onBatchComplete() } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.java deleted file mode 100644 index ee3d19c746c840..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.java +++ /dev/null @@ -1,38 +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.bridge; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; - -/** - * Annotation which is used to mark methods that are exposed to React Native. - * - *

This applies to derived classes of {@link BaseJavaModule}, which will generate a list of - * exported methods by searching for those which are annotated with this annotation and adding a JS - * callback for each. - */ -@Retention(RUNTIME) -public @interface ReactMethod { - /** - * Whether the method can be called from JS synchronously **on the JS thread**, possibly returning - * a result. - * - *

WARNING: in the vast majority of cases, you should leave this to false which allows your - * native module methods to be called asynchronously: calling methods synchronously can have - * strong performance penalties and introduce threading-related bugs to your native modules. - * - *

In order to support remote debugging, both the method args and return type must be - * serializable to JSON: this means that we only support the same args as {@link ReactMethod}, and - * the hook can only be void or return JSON values (e.g. bool, number, String, {@link - * WritableMap}, or {@link WritableArray}). Calling these methods when running under the websocket - * executor is currently not supported. - */ - boolean isBlockingSynchronousMethod() default false; -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.kt new file mode 100644 index 00000000000000..2f79ea0a3ee3fd --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMethod.kt @@ -0,0 +1,33 @@ +/* + * 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.bridge +/** + * Annotation which is used to mark methods that are exposed to React Native. + * + * This applies to derived classes of [BaseJavaModule], which will generate a list of exported + * methods by searching for those which are annotated with this annotation and adding a JS callback + * for each. + */ +@Retention(AnnotationRetention.RUNTIME) +public annotation class ReactMethod( + /** + * Whether the method can be called from JS synchronously **on the JS thread**, possibly + * returning a result. + * + * WARNING: in the vast majority of cases, you should leave this to false which allows your + * native module methods to be called asynchronously: calling methods synchronously can have + * strong performance penalties and introduce threading-related bugs to your native modules. + * + * In order to support remote debugging, both the method args and return type must be + * serializable to JSON: this means that we only support the same args as [ReactMethod], and the + * hook can only be void or return JSON values (e.g. bool, number, String, [ ], or + * [WritableArray]). Calling these methods when running under the websocket executor is + * currently not supported. + */ + public val isBlockingSynchronousMethod: Boolean = false +) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.java deleted file mode 100644 index 37d3ef1ac331fc..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.java +++ /dev/null @@ -1,17 +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.bridge; - -import com.facebook.proguard.annotations.DoNotStrip; - -/** - * @deprecated Use {@link TurboModule} to identify generated specs - */ -@DoNotStrip -@Deprecated -public interface ReactModuleWithSpec {} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.kt new file mode 100644 index 00000000000000..2b942fcf634b68 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactModuleWithSpec.kt @@ -0,0 +1,14 @@ +/* + * 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.bridge + +import com.facebook.proguard.annotations.DoNotStripAny + +@DoNotStripAny +@Deprecated("Use {@link TurboModule} to identify generated specs") +public interface ReactModuleWithSpec