From c9808a16524705e413741d2e30a973c3ee663ef4 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 12 Nov 2025 10:56:49 +0100 Subject: [PATCH] Remove `onUpdate` from discrete gestures --- .../src/v3/hooks/gestures/fling/useFling.ts | 21 +++++++------- .../src/v3/hooks/gestures/hover/useHover.ts | 21 +++++++------- .../hooks/gestures/longPress/useLongPress.ts | 29 ++++++++++--------- .../src/v3/hooks/gestures/manual/useManual.ts | 17 ++++++----- .../src/v3/hooks/gestures/native/useNative.ts | 23 ++++++++------- .../src/v3/hooks/gestures/pan/usePan.ts | 15 +++++----- .../src/v3/hooks/gestures/pinch/usePinch.ts | 21 +++++++------- .../v3/hooks/gestures/rotation/useRotation.ts | 23 ++++++++------- .../src/v3/hooks/gestures/tap/useTap.ts | 26 ++++++++++------- .../src/v3/types/GestureTypes.ts | 11 +++++++ 10 files changed, 115 insertions(+), 92 deletions(-) diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/useFling.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/useFling.ts index f98656f10e..dea7a561ff 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/useFling.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/useFling.ts @@ -1,5 +1,5 @@ import { - BaseGestureConfig, + BaseDiscreteGestureConfig, ExcludeInternalConfigProps, SingleGesture, SingleGestureName, @@ -20,7 +20,7 @@ type FlingHandlerData = { type FlingGestureProperties = WithSharedValue; -type FlingGestureInternalConfig = BaseGestureConfig< +type FlingGestureInternalConfig = BaseDiscreteGestureConfig< FlingHandlerData, FlingGestureProperties >; @@ -28,19 +28,20 @@ type FlingGestureInternalConfig = BaseGestureConfig< export type FlingGestureConfig = ExcludeInternalConfigProps; -export function useFling(config: FlingGestureConfig) { - const flingConfig = cloneConfig( - config - ); - - return useGesture(SingleGestureName.Fling, flingConfig); -} - export type FlingGestureStateChangeEvent = GestureStateChangeEvent; + export type FlingGestureUpdateEvent = GestureUpdateEvent; export type FlingGesture = SingleGesture< FlingHandlerData, FlingGestureProperties >; + +export function useFling(config: FlingGestureConfig): FlingGesture { + const flingConfig = cloneConfig( + config + ); + + return useGesture(SingleGestureName.Fling, flingConfig); +} diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/useHover.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/useHover.ts index 6f51060dfa..9713ee9c1f 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/useHover.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/useHover.ts @@ -37,6 +37,16 @@ type HoverGestureInternalConfig = BaseGestureConfig< export type HoverGestureConfig = ExcludeInternalConfigProps; +export type HoverGestureStateChangeEvent = + GestureStateChangeEvent; + +export type HoverGestureUpdateEvent = GestureUpdateEvent; + +export type HoverGesture = SingleGesture< + HoverHandlerData, + HoverGestureProperties +>; + function diffCalculator( current: HandlerData, previous: HandlerData | null @@ -48,7 +58,7 @@ function diffCalculator( }; } -export function useHover(config: HoverGestureConfig) { +export function useHover(config: HoverGestureConfig): HoverGesture { const hoverConfig = cloneConfig( config ); @@ -57,12 +67,3 @@ export function useHover(config: HoverGestureConfig) { return useGesture(SingleGestureName.Hover, hoverConfig); } - -export type HoverGestureStateChangeEvent = - GestureStateChangeEvent; -export type HoverGestureUpdateEvent = GestureUpdateEvent; - -export type HoverGesture = SingleGesture< - HoverHandlerData, - HoverGestureProperties ->; diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPress.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPress.ts index ace5b20edb..9061388ff6 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPress.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPress.ts @@ -1,5 +1,5 @@ import { - BaseGestureConfig, + BaseDiscreteGestureConfig, ExcludeInternalConfigProps, SingleGesture, SingleGestureName, @@ -29,14 +29,25 @@ type LongPressGestureInternalProperties = WithSharedValue; export type LongPressGestureConfig = ExcludeInternalConfigProps< - BaseGestureConfig + BaseDiscreteGestureConfig >; -type LongPressGestureInternalConfig = BaseGestureConfig< +type LongPressGestureInternalConfig = BaseDiscreteGestureConfig< LongPressHandlerData, LongPressGestureInternalProperties >; +export type LongPressGestureStateChangeEvent = + GestureStateChangeEvent; + +export type LongPressGestureUpdateEvent = + GestureUpdateEvent; + +export type LongPressGesture = SingleGesture< + LongPressHandlerData, + LongPressGestureProperties +>; + const LongPressPropsMapping = new Map< keyof LongPressGestureProperties, keyof LongPressGestureInternalProperties @@ -45,7 +56,7 @@ const LongPressPropsMapping = new Map< ['maxDistance', 'maxDist'], ]); -export function useLongPress(config: LongPressGestureConfig) { +export function useLongPress(config: LongPressGestureConfig): LongPressGesture { const longPressConfig = cloneConfig< LongPressHandlerData, LongPressGestureInternalProperties @@ -65,13 +76,3 @@ export function useLongPress(config: LongPressGestureConfig) { longPressConfig ); } - -export type LongPressGestureStateChangeEvent = - GestureStateChangeEvent; -export type LongPressGestureUpdateEvent = - GestureUpdateEvent; - -export type LongPressGesture = SingleGesture< - LongPressHandlerData, - LongPressGestureProperties ->; diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/useManual.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/useManual.ts index 873d2cf3ae..1f364cdbcf 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/useManual.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/useManual.ts @@ -18,17 +18,10 @@ type ManualGestureInternalConfig = BaseGestureConfig< ManualHandlerData, ManualGestureProperties >; + export type ManualGestureConfig = ExcludeInternalConfigProps; -export function useManual(config: ManualGestureConfig) { - const manualConfig = cloneConfig( - config - ); - - return useGesture(SingleGestureName.Manual, manualConfig); -} - export type ManualGestureStateChangeEvent = GestureStateChangeEvent; export type ManualGestureUpdateEvent = GestureUpdateEvent; @@ -37,3 +30,11 @@ export type ManualGesture = SingleGesture< ManualHandlerData, ManualGestureProperties >; + +export function useManual(config: ManualGestureConfig): ManualGesture { + const manualConfig = cloneConfig( + config + ); + + return useGesture(SingleGestureName.Manual, manualConfig); +} diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/useNative.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/useNative.ts index 0ca8d96d5b..6b9d5a30e6 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/useNative.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/useNative.ts @@ -1,5 +1,5 @@ import { - BaseGestureConfig, + BaseDiscreteGestureConfig, ExcludeInternalConfigProps, SingleGesture, SingleGestureName, @@ -18,7 +18,7 @@ type NativeViewHandlerData = { type NativeViewGestureProperties = WithSharedValue; -type NativeViewGestureInternalConfig = BaseGestureConfig< +type NativeViewGestureInternalConfig = BaseDiscreteGestureConfig< NativeViewHandlerData, NativeViewGestureProperties >; @@ -26,17 +26,9 @@ type NativeViewGestureInternalConfig = BaseGestureConfig< export type NativeViewGestureConfig = ExcludeInternalConfigProps; -export function useNative(config: NativeViewGestureConfig) { - const nativeConfig = cloneConfig< - NativeViewHandlerData, - NativeViewGestureProperties - >(config); - - return useGesture(SingleGestureName.Native, nativeConfig); -} - export type NativeGestureStateChangeEvent = GestureStateChangeEvent; + export type NativeGestureUpdateEvent = GestureUpdateEvent; @@ -44,3 +36,12 @@ export type NativeGesture = SingleGesture< NativeViewHandlerData, NativeViewGestureProperties >; + +export function useNative(config: NativeViewGestureConfig): NativeGesture { + const nativeConfig = cloneConfig< + NativeViewHandlerData, + NativeViewGestureProperties + >(config); + + return useGesture(SingleGestureName.Native, nativeConfig); +} diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePan.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePan.ts index 7cd81de845..351b137222 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePan.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePan.ts @@ -51,6 +51,13 @@ type PanGestureInternalConfig = BaseGestureConfig< PanGestureInternalProperties >; +export type PanGestureStateChangeEvent = + GestureStateChangeEvent; + +export type PanGestureUpdateEvent = GestureUpdateEvent; + +export type PanGesture = SingleGesture; + const PanPropsMapping = new Map< keyof PanGestureProperties, keyof PanGestureInternalProperties @@ -154,7 +161,7 @@ function diffCalculator( }; } -export function usePan(config: PanGestureConfig) { +export function usePan(config: PanGestureConfig): PanGesture { if (__DEV__) { validatePanConfig(config); } @@ -177,9 +184,3 @@ export function usePan(config: PanGestureConfig) { panConfig ); } - -export type PanGestureStateChangeEvent = - GestureStateChangeEvent; -export type PanGestureUpdateEvent = GestureUpdateEvent; - -export type PanGesture = SingleGesture; diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/usePinch.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/usePinch.ts index 26f55ef749..3b3f7b31d8 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/usePinch.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/usePinch.ts @@ -29,6 +29,16 @@ type PinchGestureInternalConfig = BaseGestureConfig< export type PinchGestureConfig = ExcludeInternalConfigProps; +export type PinchGestureStateChangeEvent = + GestureStateChangeEvent; + +export type PinchGestureUpdateEvent = GestureUpdateEvent; + +export type PinchGesture = SingleGesture< + PinchHandlerData, + PinchGestureProperties +>; + function diffCalculator( current: HandlerData, previous: HandlerData | null @@ -39,7 +49,7 @@ function diffCalculator( }; } -export function usePinch(config: PinchGestureConfig) { +export function usePinch(config: PinchGestureConfig): PinchGesture { const pinchConfig = cloneConfig( config ); @@ -48,12 +58,3 @@ export function usePinch(config: PinchGestureConfig) { return useGesture(SingleGestureName.Pinch, pinchConfig); } - -export type PinchGestureStateChangeEvent = - GestureStateChangeEvent; -export type PinchGestureUpdateEvent = GestureUpdateEvent; - -export type PinchGesture = SingleGesture< - PinchHandlerData, - PinchGestureProperties ->; diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/useRotation.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/useRotation.ts index 3893cafb10..cf45cbc0ba 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/useRotation.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/useRotation.ts @@ -29,6 +29,17 @@ type RotationGestureInternalConfig = BaseGestureConfig< export type RotationGestureConfig = ExcludeInternalConfigProps; +export type RotationGestureStateChangeEvent = + GestureStateChangeEvent; + +export type RotationGestureUpdateEvent = + GestureUpdateEvent; + +export type RotationGesture = SingleGesture< + RotationHandlerData, + RotationGestureProperties +>; + function diffCalculator( current: HandlerData, previous: HandlerData | null @@ -41,7 +52,7 @@ function diffCalculator( }; } -export function useRotation(config: RotationGestureConfig) { +export function useRotation(config: RotationGestureConfig): RotationGesture { const rotationConfig = cloneConfig< RotationHandlerData, RotationGestureProperties @@ -52,13 +63,3 @@ export function useRotation(config: RotationGestureConfig) { return useGesture(SingleGestureName.Rotation, rotationConfig); } - -export type RotationGestureStateChangeEvent = - GestureStateChangeEvent; -export type RotationGestureUpdateEvent = - GestureUpdateEvent; - -export type RotationGesture = SingleGesture< - RotationHandlerData, - RotationGestureProperties ->; diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTap.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTap.ts index 74387c08b3..b9c4276353 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTap.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTap.ts @@ -1,9 +1,9 @@ import { - BaseGestureConfig, + BaseDiscreteGestureConfig, ExcludeInternalConfigProps, GestureStateChangeEvent, GestureUpdateEvent, - SingleGesture, + DiscreteSingleGesture, SingleGestureName, WithSharedValue, } from '../../../types'; @@ -26,14 +26,24 @@ type TapGestureProperties = WithSharedValue; type TapGestureInternalProperties = WithSharedValue; export type TapGestureConfig = ExcludeInternalConfigProps< - BaseGestureConfig + BaseDiscreteGestureConfig >; -type TapGestureInternalConfig = BaseGestureConfig< +type TapGestureInternalConfig = BaseDiscreteGestureConfig< TapHandlerData, TapGestureInternalProperties >; +export type TapGestureStateChangeEvent = + GestureStateChangeEvent; + +export type TapGestureUpdateEvent = GestureUpdateEvent; + +export type TapGesture = DiscreteSingleGesture< + TapHandlerData, + TapGestureProperties +>; + const TapPropsMapping = new Map< keyof TapGestureProperties, keyof TapGestureInternalProperties @@ -43,7 +53,7 @@ const TapPropsMapping = new Map< ['maxDelay', 'maxDelayMs'], ]); -export function useTap(config: TapGestureConfig) { +export function useTap(config: TapGestureConfig): TapGesture { const tapConfig = cloneConfig( config ); @@ -58,9 +68,3 @@ export function useTap(config: TapGestureConfig) { tapConfig ); } - -export type TapGestureStateChangeEvent = - GestureStateChangeEvent; -export type TapGestureUpdateEvent = GestureUpdateEvent; - -export type TapGesture = SingleGesture; diff --git a/packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts b/packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts index a2a8df21b8..07860702fe 100644 --- a/packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts @@ -22,6 +22,11 @@ export type BaseGestureConfig = ExternalRelations & InternalConfigProps & CommonGestureConfig; +export type BaseDiscreteGestureConfig = Omit< + BaseGestureConfig, + 'onUpdate' +>; + export type SingleGesture = { tag: number; type: SingleGestureName; @@ -30,6 +35,12 @@ export type SingleGesture = { gestureRelations: GestureRelations; }; +export type DiscreteSingleGesture = { + [K in keyof SingleGesture]: K extends 'config' + ? Omit[K], 'onUpdate'> + : SingleGesture[K]; +}; + export type ComposedGesture = { tags: number[]; type: ComposedGestureName;