Skip to content

Commit

Permalink
Kotlinify functional interfaces in react.bridge (facebook#44546)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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.

Differential Revision: D57253634
  • Loading branch information
rshest authored and facebook-github-bot committed May 16, 2024
1 parent d94c4c4 commit 6cb2d2c
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 83 deletions.
14 changes: 14 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6cb2d2c

Please sign in to comment.