From 1cbe5376ba91084b4ba726b5eee13eb33936a72f Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 02:00:36 -0700 Subject: [PATCH] Kotlinify ScrollEventType (#43827) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43827 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: arushikesarwani94 Differential Revision: D55708353 fbshipit-source-id: 30a31e7eb9e6ad59b7c90468f9e6f55c91c579a8 --- .../ReactAndroid/api/ReactAndroid.api | 7 +++- .../react/views/scroll/ScrollEventType.java | 37 ------------------- .../react/views/scroll/ScrollEventType.kt | 29 +++++++++++++++ 3 files changed, 35 insertions(+), 38 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index bbad17e405b..4a63b8cda1e 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -6741,15 +6741,20 @@ public final class com/facebook/react/views/scroll/ScrollEvent$Companion { public final class com/facebook/react/views/scroll/ScrollEventType : java/lang/Enum { public static final field BEGIN_DRAG Lcom/facebook/react/views/scroll/ScrollEventType; + public static final field Companion Lcom/facebook/react/views/scroll/ScrollEventType$Companion; public static final field END_DRAG Lcom/facebook/react/views/scroll/ScrollEventType; 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 getJSEventName (Lcom/facebook/react/views/scroll/ScrollEventType;)Ljava/lang/String; + 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; } +public final class com/facebook/react/views/scroll/ScrollEventType$Companion { + public final fun getJSEventName (Lcom/facebook/react/views/scroll/ScrollEventType;)Ljava/lang/String; +} + public class com/facebook/react/views/swiperefresh/ReactSwipeRefreshLayout : androidx/swiperefreshlayout/widget/SwipeRefreshLayout { public fun (Lcom/facebook/react/bridge/ReactContext;)V public fun onInterceptTouchEvent (Landroid/view/MotionEvent;)Z diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.java deleted file mode 100644 index b58173850da..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.java +++ /dev/null @@ -1,37 +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.scroll; - -import com.facebook.infer.annotation.Nullsafe; - -/** Scroll event types that JS module RCTEventEmitter can understand */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public enum ScrollEventType { - BEGIN_DRAG, - END_DRAG, - SCROLL, - MOMENTUM_BEGIN, - MOMENTUM_END; - - public static String getJSEventName(ScrollEventType type) { - switch (type) { - case BEGIN_DRAG: - return "topScrollBeginDrag"; - case END_DRAG: - return "topScrollEndDrag"; - case SCROLL: - return "topScroll"; - case MOMENTUM_BEGIN: - return "topMomentumScrollBegin"; - case MOMENTUM_END: - return "topMomentumScrollEnd"; - default: - throw new IllegalArgumentException("Unsupported ScrollEventType: " + type); - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.kt new file mode 100644 index 00000000000..94d8d82eba0 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEventType.kt @@ -0,0 +1,29 @@ +/* + * 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.scroll + +/** Scroll event types that JS module RCTEventEmitter can understand */ +public enum class ScrollEventType { + BEGIN_DRAG, + END_DRAG, + SCROLL, + MOMENTUM_BEGIN, + MOMENTUM_END; + + public companion object { + @JvmStatic + public fun getJSEventName(type: ScrollEventType): String = + when (type) { + BEGIN_DRAG -> "topScrollBeginDrag" + END_DRAG -> "topScrollEndDrag" + SCROLL -> "topScroll" + MOMENTUM_BEGIN -> "topMomentumScrollBegin" + MOMENTUM_END -> "topMomentumScrollEnd" + } + } +}