From 824309e57fca039c1eda510a7c50243c1c2551a8 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:27 -0700 Subject: [PATCH 1/6] Kotlinify DoubleTapReloadRecognizer Differential Revision: https://internalfb.com/D55747942 --- .../ReactAndroid/api/ReactAndroid.api | 4 +- .../devsupport/DoubleTapReloadRecognizer.java | 45 ------------------- .../devsupport/DoubleTapReloadRecognizer.kt | 39 ++++++++++++++++ 3 files changed, 41 insertions(+), 47 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 00819defed36..20c642cdf067 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2159,9 +2159,9 @@ public abstract interface class com/facebook/react/devsupport/DevSupportManagerF public abstract fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZLcom/facebook/react/devsupport/interfaces/RedBoxHandler;Lcom/facebook/react/devsupport/interfaces/DevBundleDownloadListener;ILjava/util/Map;Lcom/facebook/react/common/SurfaceDelegateFactory;Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;)Lcom/facebook/react/devsupport/interfaces/DevSupportManager; } -public class com/facebook/react/devsupport/DoubleTapReloadRecognizer { +public final class com/facebook/react/devsupport/DoubleTapReloadRecognizer { public fun ()V - public fun didDoubleTapR (ILandroid/view/View;)Z + public final fun didDoubleTapR (ILandroid/view/View;)Z } public abstract interface class com/facebook/react/devsupport/HMRClient : com/facebook/react/bridge/JavaScriptModule { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.java deleted file mode 100644 index 791943dc43c1..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.java +++ /dev/null @@ -1,45 +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.devsupport; - -import android.os.Handler; -import android.view.KeyEvent; -import android.view.View; -import android.widget.EditText; -import com.facebook.infer.annotation.Nullsafe; - -/** - * A class allows recognizing double key tap of "R", used to reload JS in {@link - * AbstractReactActivity}, {@link RedBoxDialogSurfaceDelegate} and {@link ReactActivity}. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class DoubleTapReloadRecognizer { - private boolean mDoRefresh = false; - private static final long DOUBLE_TAP_DELAY = 200; - - public boolean didDoubleTapR(int keyCode, View view) { - if (keyCode == KeyEvent.KEYCODE_R && !(view instanceof EditText)) { - if (mDoRefresh) { - mDoRefresh = false; - return true; - } else { - mDoRefresh = true; - new Handler() - .postDelayed( - new Runnable() { - @Override - public void run() { - mDoRefresh = false; - } - }, - DOUBLE_TAP_DELAY); - } - } - return false; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.kt new file mode 100644 index 000000000000..0bcaadf8ea21 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DoubleTapReloadRecognizer.kt @@ -0,0 +1,39 @@ +/* + * 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.devsupport + +import android.os.Handler +import android.os.Looper +import android.view.KeyEvent +import android.view.View +import android.widget.EditText + +/** + * A class allows recognizing double key tap of "R", used to reload JS in [AbstractReactActivity], + * [RedBoxDialogSurfaceDelegate] and [ReactActivity]. + */ +public class DoubleTapReloadRecognizer { + private var doRefresh = false + + public fun didDoubleTapR(keyCode: Int, view: View): Boolean { + if (keyCode == KeyEvent.KEYCODE_R && view !is EditText) { + if (doRefresh) { + doRefresh = false + return true + } else { + doRefresh = true + Handler(Looper.getMainLooper()).postDelayed({ doRefresh = false }, DOUBLE_TAP_DELAY) + } + } + return false + } + + private companion object { + private const val DOUBLE_TAP_DELAY: Long = 200 + } +} From 34b47a96ee1732d209ae3722d02451c843d236a4 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:27 -0700 Subject: [PATCH 2/6] Kotlinify ViewGroupClickEvent Differential Revision: D55749364 --- .../ReactAndroid/api/ReactAndroid.api | 3 +- .../react/views/view/ViewGroupClickEvent.java | 46 ------------------- .../react/views/view/ViewGroupClickEvent.kt | 31 +++++++++++++ 3 files changed, 32 insertions(+), 48 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 20c642cdf067..60286a40f67e 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7775,11 +7775,10 @@ public class com/facebook/react/views/view/ReactViewManager$$PropsSetter : com/f public fun setProperty (Lcom/facebook/react/views/view/ReactViewManager;Lcom/facebook/react/views/view/ReactViewGroup;Ljava/lang/String;Ljava/lang/Object;)V } -public class com/facebook/react/views/view/ViewGroupClickEvent : com/facebook/react/uimanager/events/Event { +public final class com/facebook/react/views/view/ViewGroupClickEvent : com/facebook/react/uimanager/events/Event { public fun (I)V public fun (II)V public fun canCoalesce ()Z - protected fun getEventData ()Lcom/facebook/react/bridge/WritableMap; public fun getEventName ()Ljava/lang/String; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.java deleted file mode 100644 index e6d7c0f10afe..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.java +++ /dev/null @@ -1,46 +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.views.view; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.common.ViewUtil; -import com.facebook.react.uimanager.events.Event; - -/** Represents a Click on the ReactViewGroup */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ViewGroupClickEvent extends Event { - private static final String EVENT_NAME = "topClick"; - - @Deprecated - public ViewGroupClickEvent(int viewId) { - this(ViewUtil.NO_SURFACE_ID, viewId); - } - - public ViewGroupClickEvent(int surfaceId, int viewId) { - super(surfaceId, viewId); - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Nullable - @Override - protected WritableMap getEventData() { - return Arguments.createMap(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.kt new file mode 100644 index 000000000000..dfcc5954783d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ViewGroupClickEvent.kt @@ -0,0 +1,31 @@ +/* + * 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.views.view + +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.common.ViewUtil +import com.facebook.react.uimanager.events.Event + +/** Represents a Click on the ReactViewGroup */ +public class ViewGroupClickEvent(surfaceId: Int, viewId: Int) : + Event(surfaceId, viewId) { + + @Deprecated("Use the constructor with surfaceId and viewId parameters.") + public constructor(viewId: Int) : this(ViewUtil.NO_SURFACE_ID, viewId) + + override public fun getEventName(): String = EVENT_NAME + + override public fun canCoalesce(): Boolean = false + + override protected fun getEventData(): WritableMap = Arguments.createMap() + + private companion object { + private const val EVENT_NAME: String = "topClick" + } +} From 22d55ab7c78e1e6c086cd8d442fe67b040cf4213 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:27 -0700 Subject: [PATCH 3/6] Kotlinify NativeGestureUtil Summary: Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: https://internalfb.com/D55750840 --- .../ReactAndroid/api/ReactAndroid.api | 8 ++--- ...eGestureUtil.java => NativeGestureUtil.kt} | 31 ++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/{NativeGestureUtil.java => NativeGestureUtil.kt} (60%) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 60286a40f67e..46c88e773001 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -5515,10 +5515,10 @@ public class com/facebook/react/uimanager/events/FabricEventDispatcher : com/fac public fun unregisterEventEmitter (I)V } -public class com/facebook/react/uimanager/events/NativeGestureUtil { - public fun ()V - public static fun notifyNativeGestureEnded (Landroid/view/View;Landroid/view/MotionEvent;)V - public static fun notifyNativeGestureStarted (Landroid/view/View;Landroid/view/MotionEvent;)V +public final class com/facebook/react/uimanager/events/NativeGestureUtil { + public static final field INSTANCE Lcom/facebook/react/uimanager/events/NativeGestureUtil; + public static final fun notifyNativeGestureEnded (Landroid/view/View;Landroid/view/MotionEvent;)V + public static final fun notifyNativeGestureStarted (Landroid/view/View;Landroid/view/MotionEvent;)V } public class com/facebook/react/uimanager/events/PointerEvent : com/facebook/react/uimanager/events/Event { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.kt similarity index 60% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.kt index 940f15eec827..00441e58fefc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.kt @@ -5,17 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.uimanager.events; +package com.facebook.react.uimanager.events -import android.view.MotionEvent; -import android.view.View; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.uimanager.RootView; -import com.facebook.react.uimanager.RootViewUtil; +import android.view.MotionEvent +import android.view.View +import com.facebook.react.uimanager.RootViewUtil /** Utilities for native Views that interpret native gestures (e.g. ScrollView, ViewPager, etc.). */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class NativeGestureUtil { +public object NativeGestureUtil { /** * Helper method that should be called when a native view starts a native gesture (e.g. a native @@ -25,11 +22,10 @@ public class NativeGestureUtil { * @param view the View starting the native gesture * @param event the MotionEvent that caused the gesture to be started */ - public static void notifyNativeGestureStarted(View view, MotionEvent event) { - RootView rootView = RootViewUtil.getRootView(view); - if (rootView != null) { - rootView.onChildStartedNativeGesture(view, event); - } + @JvmStatic + public fun notifyNativeGestureStarted(view: View, event: MotionEvent) { + val rootView = RootViewUtil.getRootView(view) + rootView?.onChildStartedNativeGesture(view, event) } /** @@ -40,10 +36,9 @@ public static void notifyNativeGestureStarted(View view, MotionEvent event) { * @param view the View ending the native gesture * @param event the MotionEvent that caused the gesture to be ended */ - public static void notifyNativeGestureEnded(View view, MotionEvent event) { - RootView rootView = RootViewUtil.getRootView(view); - if (rootView != null) { - rootView.onChildEndedNativeGesture(view, event); - } + @JvmStatic + public fun notifyNativeGestureEnded(view: View, event: MotionEvent) { + val rootView = RootViewUtil.getRootView(view) + rootView?.onChildEndedNativeGesture(view, event) } } From d015deb47ce6ddd13cd1eecd20f7504b67f71392 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:27 -0700 Subject: [PATCH 4/6] Kotlinify DispatchIntCommandMountItem Differential Revision: https://internalfb.com/D55751796 --- .../DispatchIntCommandMountItem.java | 47 ------------------- .../mountitems/DispatchIntCommandMountItem.kt | 28 +++++++++++ 2 files changed, 28 insertions(+), 47 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java deleted file mode 100644 index 887ac2e1026b..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java +++ /dev/null @@ -1,47 +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.fabric.mounting.mountitems; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.fabric.mounting.MountingManager; - -@Nullsafe(Nullsafe.Mode.LOCAL) -final class DispatchIntCommandMountItem extends DispatchCommandMountItem { - - private final int mSurfaceId; - private final int mReactTag; - private final int mCommandId; - private final @Nullable ReadableArray mCommandArgs; - - DispatchIntCommandMountItem( - int surfaceId, int reactTag, int commandId, @Nullable ReadableArray commandArgs) { - mSurfaceId = surfaceId; - mReactTag = reactTag; - mCommandId = commandId; - mCommandArgs = commandArgs; - } - - @Override - public int getSurfaceId() { - return mSurfaceId; - } - - @Override - public void execute(@NonNull MountingManager mountingManager) { - mountingManager.receiveCommand(mSurfaceId, mReactTag, mCommandId, mCommandArgs); - } - - @Override - @NonNull - public String toString() { - return "DispatchIntCommandMountItem [" + mReactTag + "] " + mCommandId; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.kt new file mode 100644 index 000000000000..0e4a82c47daf --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.kt @@ -0,0 +1,28 @@ +/* + * 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.fabric.mounting.mountitems + +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.fabric.mounting.MountingManager + +internal class DispatchIntCommandMountItem( + private val surfaceId: Int, + private val reactTag: Int, + private val commandId: Int, + private val commandArgs: ReadableArray? +) : DispatchCommandMountItem() { + + override public fun getSurfaceId(): Int = surfaceId + + override public fun execute(mountingManager: MountingManager) { + @Suppress("DEPRECATION") + mountingManager.receiveCommand(surfaceId, reactTag, commandId, commandArgs) + } + + override public fun toString(): String = "DispatchIntCommandMountItem [$reactTag] $commandId" +} From 17dd663624007c86ea65c681554144e0a88a1c36 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:27 -0700 Subject: [PATCH 5/6] Kotlinify DispatchStringCommandMountItem Differential Revision: D55752447 --- .../DispatchStringCommandMountItem.java | 47 ------------------- .../DispatchStringCommandMountItem.kt | 27 +++++++++++ 2 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java deleted file mode 100644 index 4b68d18aef8e..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java +++ /dev/null @@ -1,47 +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.fabric.mounting.mountitems; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.fabric.mounting.MountingManager; - -@Nullsafe(Nullsafe.Mode.LOCAL) -final class DispatchStringCommandMountItem extends DispatchCommandMountItem { - - private final int mSurfaceId; - private final int mReactTag; - private final @NonNull String mCommandId; - private final @Nullable ReadableArray mCommandArgs; - - DispatchStringCommandMountItem( - int surfaceId, int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) { - mSurfaceId = surfaceId; - mReactTag = reactTag; - mCommandId = commandId; - mCommandArgs = commandArgs; - } - - @Override - public int getSurfaceId() { - return mSurfaceId; - } - - @Override - public void execute(@NonNull MountingManager mountingManager) { - mountingManager.receiveCommand(mSurfaceId, mReactTag, mCommandId, mCommandArgs); - } - - @Override - @NonNull - public String toString() { - return "DispatchStringCommandMountItem [" + mReactTag + "] " + mCommandId; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.kt new file mode 100644 index 000000000000..fc3bbebdf9a3 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.kt @@ -0,0 +1,27 @@ +/* + * 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.fabric.mounting.mountitems + +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.fabric.mounting.MountingManager + +internal class DispatchStringCommandMountItem( + private val surfaceId: Int, + private val reactTag: Int, + private val commandId: String, + private val commandArgs: ReadableArray? +) : DispatchCommandMountItem() { + + override public fun getSurfaceId(): Int = surfaceId + + override public fun execute(mountingManager: MountingManager) { + mountingManager.receiveCommand(surfaceId, reactTag, commandId, commandArgs) + } + + override public fun toString(): String = "DispatchStringCommandMountItem [$reactTag] $commandId" +} From e755b02054ade65bf97f74a6911f3627a15aa6cc Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 10:59:46 -0700 Subject: [PATCH 6/6] Kotlinify LinearCountingRetryPolicy (#43871) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43871 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: alanleedev Differential Revision: D55753695 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../jstasks/LinearCountingRetryPolicy.java | 48 ------------------- .../jstasks/LinearCountingRetryPolicy.kt | 31 ++++++++++++ 3 files changed, 32 insertions(+), 49 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 46c88e773001..191f08fac7ec 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2887,7 +2887,7 @@ public abstract interface class com/facebook/react/jstasks/HeadlessJsTaskRetryPo public abstract fun update ()Lcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy; } -public class com/facebook/react/jstasks/LinearCountingRetryPolicy : com/facebook/react/jstasks/HeadlessJsTaskRetryPolicy { +public final class com/facebook/react/jstasks/LinearCountingRetryPolicy : com/facebook/react/jstasks/HeadlessJsTaskRetryPolicy { public fun (II)V public fun canRetry ()Z public fun copy ()Lcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.java deleted file mode 100644 index a008a5aa0f8f..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.java +++ /dev/null @@ -1,48 +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.jstasks; - -import com.facebook.infer.annotation.Nullsafe; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class LinearCountingRetryPolicy implements HeadlessJsTaskRetryPolicy { - - private final int mRetryAttempts; - private final int mDelayBetweenAttemptsInMs; - - public LinearCountingRetryPolicy(int retryAttempts, int delayBetweenAttemptsInMs) { - mRetryAttempts = retryAttempts; - mDelayBetweenAttemptsInMs = delayBetweenAttemptsInMs; - } - - @Override - public boolean canRetry() { - return mRetryAttempts > 0; - } - - @Override - public int getDelay() { - return mDelayBetweenAttemptsInMs; - } - - @Override - public HeadlessJsTaskRetryPolicy update() { - final int remainingRetryAttempts = mRetryAttempts - 1; - - if (remainingRetryAttempts > 0) { - return new LinearCountingRetryPolicy(remainingRetryAttempts, mDelayBetweenAttemptsInMs); - } else { - return NoRetryPolicy.INSTANCE; - } - } - - @Override - public HeadlessJsTaskRetryPolicy copy() { - return new LinearCountingRetryPolicy(mRetryAttempts, mDelayBetweenAttemptsInMs); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.kt new file mode 100644 index 000000000000..1ba4ff038f78 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/LinearCountingRetryPolicy.kt @@ -0,0 +1,31 @@ +/* + * 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.jstasks + +public class LinearCountingRetryPolicy( + private val retryAttempts: Int, + private val delayBetweenAttemptsInMs: Int +) : HeadlessJsTaskRetryPolicy { + + override public fun canRetry(): Boolean = retryAttempts > 0 + + override public fun getDelay(): Int = delayBetweenAttemptsInMs + + override public fun update(): HeadlessJsTaskRetryPolicy { + val remainingRetryAttempts = retryAttempts - 1 + + return if (remainingRetryAttempts > 0) { + LinearCountingRetryPolicy(remainingRetryAttempts, delayBetweenAttemptsInMs) + } else { + NoRetryPolicy.INSTANCE + } + } + + override public fun copy(): HeadlessJsTaskRetryPolicy = + LinearCountingRetryPolicy(retryAttempts, delayBetweenAttemptsInMs) +}