From 2aef4418eae876c5702714030fba253c282cfcbc Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Fri, 5 Apr 2024 13:54:51 -0700 Subject: [PATCH] Kotlinify NativeGestureUtil (#43867) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43867 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: alanleedev Differential Revision: D55750840 fbshipit-source-id: 356828e6fc9c1b4c77e130cce281e5503ffb0d16 --- .../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 6f1ee6536b1..726557ab23d 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -5522,10 +5522,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 940f15eec82..00441e58fef 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 class NativeGestureUtil { * @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) } }