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 495ea9d8067..a714f92b7af 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 e7e3d580b12..59f677997b1 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 9dd9972fe52..4e86c116816 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 7808c782800..b09e7c540f7 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 ee3d19c746c..00000000000 --- 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 00000000000..2f79ea0a3ee --- /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 37d3ef1ac33..00000000000 --- 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 00000000000..2b942fcf634 --- /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