Kotlinify functional interfaces in react.bridge (#44546)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44546

# Changelog:
[Internal] -

This is the first chunk of moving all of the interfaces to Kotlin inside `react.bridge`, covering the small-ish (functional/SAM and such) interfaces.

Reviewed By: javache

Differential Revision: D57253634

fbshipit-source-id: aa26d26b9681ac7c6059c249b985ff5121ad1e9d
This commit is contained in:
Ruslan Shestopalyuk
2024-05-16 07:13:50 -07:00
committed by Facebook GitHub Bot
parent c481bce649
commit 44bac48ed6
8 changed files with 68 additions and 83 deletions
@@ -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?)
}
@@ -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.
*
* <p>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)
}
@@ -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.
*
* <p>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()
}
@@ -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()
}
@@ -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.
*
* <p>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.
*
* <p>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.
*
* <p>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;
}
@@ -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
)
@@ -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 {}
@@ -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