diff --git a/packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx b/packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx index 92ec050646..413718ee10 100644 --- a/packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx +++ b/packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx @@ -35,10 +35,12 @@ Low-level `TouchEvent` callbacks are tied to raw pointer activity. Drag out of t ## Callbacks +The signatures below use the [`Pan`](/docs/gestures/use-pan-gesture) gesture as an example. Other gestures export analogous types, for example `TapGestureBeginEvent` for the [`onBegin`](#onbegin) callback of the [`Tap`](/docs/gestures/use-tap-gesture) gesture. See [Gesture events](#gesture-events). + ### onBegin ```ts -onBegin: (event: GestureEvent) => void +onBegin: (event: PanGestureBeginEvent) => void ``` Called when a handler begins to recognize gestures. If `onBegin` was called, it is guaranteed that `onFinalize` will be called later. @@ -46,7 +48,7 @@ Called when a handler begins to recognize gestures. If `onBegin` was called, it ### onActivate ```ts -onActivate: (event: GestureEvent) => void +onActivate: (event: PanGestureActiveEvent) => void ``` Called when activation criteria for the handler are met. If `onActivate` was called, it is guaranteed that `onDeactivate` will be called later. @@ -54,7 +56,7 @@ Called when activation criteria for the handler are met. If `onActivate` was cal ### onUpdate ```ts -onUpdate: (event: GestureEvent) => void +onUpdate: (event: PanGestureActiveEvent) => void ``` Called each time a pointer tracked by the gesture changes state, typically due to movement, after the gesture has been activated. @@ -62,7 +64,7 @@ Called each time a pointer tracked by the gesture changes state, typically due t ### onDeactivate ```ts -onDeactivate: (event: GestureEndEvent) => void +onDeactivate: (event: PanGestureDeactivateEvent) => void ``` Called when handler stops recognizing gestures, but only if the handler activated. It is called before `onFinalize`. The event object contains a `canceled` property — if the gesture was interrupted, `canceled` is set to `true`. Otherwise it is set to `false`. @@ -70,7 +72,7 @@ Called when handler stops recognizing gestures, but only if the handler activate ### onFinalize ```ts -onFinalize: (event: GestureEndEvent) => void +onFinalize: (event: PanGestureFinalizeEvent) => void ``` Called when handler stops recognizing gestures. The event object contains a `canceled` property — if the handler failed to activate or was interrupted, `canceled` is set to `true`. If the handler managed to activate and completed successfully, `canceled` is set to `false` and `onFinalize` will be called right after `onDeactivate`. @@ -109,22 +111,23 @@ Called when there will be no more information about this pointer. It may be call ## Events -### GestureEvent +### Gesture events + +Each gesture exports one event type per callback. For example, the [`Pan`](/docs/gestures/use-pan-gesture) gesture exports `PanGestureBeginEvent`, `PanGestureActiveEvent`, `PanGestureDeactivateEvent` and `PanGestureFinalizeEvent`. Other gestures follow the same pattern, such as `TapGestureBeginEvent` for [`Tap`](/docs/gestures/use-tap-gesture). [`onUpdate`](#onupdate) receives the same event type as [`onActivate`](#onactivate). + +All of them share the shape below, shown for `PanGestureBeginEvent`, along with the gesture-specific data listed on each gesture's page: = { +type PanGestureBeginEvent = { handlerTag: number; numberOfPointers: number; pointerType: PointerType; -} & HandlerData; - -export type GestureEndEvent = { - canceled: boolean; -} & GestureEvent; + // ... +}; export enum PointerType { TOUCH, @@ -135,11 +138,9 @@ export enum PointerType { } `}/> -`GestureEvent` contains properties common to all gestures (`handlerTag`, `numberOfPointers`, `pointerType`) along with gesture-specific data defined in each gesture's documentation. - -### GestureEndEvent +[`onBegin`](#onbegin) and [`onFinalize`](#onfinalize) receive only the data available before the gesture activates. [`onActivate`](#onactivate), [`onUpdate`](#onupdate) and [`onDeactivate`](#ondeactivate) additionally carry the data computed while the gesture is active, such as [`translationX`](/docs/gestures/use-pan-gesture#translationx) of [`Pan`](/docs/gestures/use-pan-gesture) or [`scale`](/docs/gestures/use-pinch-gesture#scale) of [`Pinch`](/docs/gestures/use-pinch-gesture). -`GestureEndEvent` extends `GestureEvent` with a `canceled` property. It is used in the [`onDeactivate`](#ondeactivate) and [`onFinalize`](#onfinalize) callbacks. When `canceled` is `true`, the gesture was interrupted or failed to activate. When `false`, the gesture completed successfully. +Events passed to [`onDeactivate`](#ondeactivate) and [`onFinalize`](#onfinalize) also contain a `canceled` property. When `canceled` is `true`, the gesture was interrupted or failed to activate. ### TouchEvent diff --git a/packages/docs-gesture-handler/docs/gestures/_shared/base-continuous-gesture-callbacks.mdx b/packages/docs-gesture-handler/docs/gestures/_shared/base-continuous-gesture-callbacks.mdx index bc5f528379..f2727150a2 100644 --- a/packages/docs-gesture-handler/docs/gestures/_shared/base-continuous-gesture-callbacks.mdx +++ b/packages/docs-gesture-handler/docs/gestures/_shared/base-continuous-gesture-callbacks.mdx @@ -4,7 +4,7 @@ import CodeBlock from '@theme/CodeBlock'; { - {`onUpdate: (event: ${props.gesture}HandlerData) => void`} + {`onUpdate: (event: ${props.gesture}GestureActiveEvent) => void`} } diff --git a/packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-callbacks.mdx b/packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-callbacks.mdx index c91ffd35e2..63d57748f5 100644 --- a/packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-callbacks.mdx +++ b/packages/docs-gesture-handler/docs/gestures/_shared/base-gesture-callbacks.mdx @@ -4,7 +4,7 @@ import CodeBlock from '@theme/CodeBlock'; { - {`onBegin: (event: ${props.gesture}HandlerData) => void`} + {`onBegin: (event: ${props.gesture}GestureBeginEvent) => void`} } @@ -14,7 +14,7 @@ Set the callback that is being called when given gesture handler starts receivin { - {`onActivate: (event: ${props.gesture}HandlerData) => void`} + {`onActivate: (event: ${props.gesture}GestureActiveEvent) => void`} } @@ -24,7 +24,7 @@ Set the callback that is being called when the gesture is recognized by the hand { - {`onDeactivate: (event: ${props.gesture}HandlerData & { canceled: boolean }) => void`} + {`onDeactivate: (event: ${props.gesture}GestureDeactivateEvent) => void`} } @@ -34,7 +34,7 @@ Set the callback that is being called when the gesture that was recognized by th { - {`onFinalize: (event: ${props.gesture}HandlerData & { canceled: boolean }) => void`} + {`onFinalize: (event: ${props.gesture}GestureFinalizeEvent) => void`} } diff --git a/packages/docs-gesture-handler/docs/gestures/use-native-gesture.mdx b/packages/docs-gesture-handler/docs/gestures/use-native-gesture.mdx index 64e8bfd25d..2048912fc6 100644 --- a/packages/docs-gesture-handler/docs/gestures/use-native-gesture.mdx +++ b/packages/docs-gesture-handler/docs/gestures/use-native-gesture.mdx @@ -139,7 +139,7 @@ On iOS this controls [`delaysContentTouches`](https://developer.apple.com/docume ## Callbacks - + ## Event data diff --git a/packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx b/packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx index 5ae03bf5c0..c726cbab71 100644 --- a/packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx +++ b/packages/docs-gesture-handler/docs/guides/upgrading-to-3.mdx @@ -149,7 +149,7 @@ The `state` and `oldState` properties are no longer available in event objects. ### Event types -The types of events have been unified for all callbacks. Each event falls into one of two categories: [`GestureEvent`](/docs/fundamentals/callbacks-events#gestureevent) for gesture callbacks, or [`GestureTouchEvent`](/docs/fundamentals/callbacks-events#touchevent) for `TouchEvent` callbacks. +The types of events have been unified for all callbacks. Each event falls into one of two categories: a [gesture-specific event type](/docs/fundamentals/callbacks-events#gesture-events) such as `PanGestureBeginEvent` for gesture callbacks, or [`GestureTouchEvent`](/docs/fundamentals/callbacks-events#touchevent) for `TouchEvent` callbacks. ### StateManager diff --git a/packages/react-native-gesture-handler/__typetests__/gestureEventTypesTest.ts b/packages/react-native-gesture-handler/__typetests__/gestureEventTypesTest.ts new file mode 100644 index 0000000000..ef4fc9a90b --- /dev/null +++ b/packages/react-native-gesture-handler/__typetests__/gestureEventTypesTest.ts @@ -0,0 +1,65 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import type { + HoverGestureConfig, + HoverGestureDeactivateEvent, + HoverGestureFinalizeEvent, + PanGestureActiveEvent, + PanGestureBeginEvent, + PanGestureConfig, + PanGestureDeactivateEvent, + PanGestureEvent, + PanGestureFinalizeEvent, + TapGestureActiveEvent, + TapGestureBeginEvent, + TapGestureConfig, + TapGestureDeactivateEvent, + TapGestureFinalizeEvent, +} from '../src/v3'; + +type StaticAssert = T; +type Same = A extends B ? (B extends A ? true : false) : false; +type EventOf = Parameters< + NonNullable void>> +>[0]; + +// The exported event aliases must match the callback parameter types exactly, +// both for a gesture with extended data (Pan) and one without (Tap). +type PanBegin = StaticAssert< + Same> +>; +type PanActive = StaticAssert< + Same> +>; +type PanDeactivate = StaticAssert< + Same> +>; +type PanFinalize = StaticAssert< + Same> +>; +type PanDeprecated = StaticAssert>; + +type TapBegin = StaticAssert< + Same> +>; +type TapActive = StaticAssert< + Same> +>; +type TapDeactivate = StaticAssert< + Same> +>; +type TapFinalize = StaticAssert< + Same> +>; + +// Deactivate carries the extended data, Finalize only the base data. +type HoverDeactivate = StaticAssert< + Same> +>; +type HoverFinalize = StaticAssert< + Same> +>; +type HoverEndEventsDiffer = StaticAssert< + Same extends false + ? true + : false +>; diff --git a/packages/react-native-gesture-handler/src/components/Pressable/utils.ts b/packages/react-native-gesture-handler/src/components/Pressable/utils.ts index ca655a1a31..9df34be97a 100644 --- a/packages/react-native-gesture-handler/src/components/Pressable/utils.ts +++ b/packages/react-native-gesture-handler/src/components/Pressable/utils.ts @@ -9,8 +9,10 @@ import type { HoverGestureHandlerEventPayload, LongPressGestureHandlerEventPayload, } from '../../handlers/GestureHandlerEventPayload'; -import type { HoverGestureEvent, LongPressGestureEvent } from '../../v3'; -import type { HoverGestureActiveEvent } from '../../v3/hooks'; +import type { + HoverGestureBeginEvent, + HoverGestureFinalizeEvent, +} from '../../v3'; import type { InnerPressableEvent, PressableDimensions, @@ -52,9 +54,8 @@ const gestureToPressEvent = ( | GestureStateChangeEvent< HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload > - | HoverGestureEvent - | HoverGestureActiveEvent - | LongPressGestureEvent, + | HoverGestureBeginEvent + | HoverGestureFinalizeEvent, timestamp: number, targetId: number ): InnerPressableEvent => ({ @@ -84,9 +85,8 @@ const gestureToPressableEvent = ( | GestureStateChangeEvent< HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload > - | HoverGestureEvent - | HoverGestureActiveEvent - | LongPressGestureEvent + | HoverGestureBeginEvent + | HoverGestureFinalizeEvent ): PressableEvent => { const timestamp = Date.now(); diff --git a/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx b/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx index b3f83c437a..1626452b49 100644 --- a/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx +++ b/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx @@ -45,7 +45,7 @@ import { InterceptingGestureDetector, VirtualGestureDetector, } from '../v3/detectors'; -import type { PanGestureActiveEvent } from '../v3/hooks/gestures'; +import type { PanGestureDeactivateEvent } from '../v3/hooks/gestures'; import { usePanGesture, useTapGesture } from '../v3/hooks/gestures'; import type { WithSharedValue } from '../v3/types'; @@ -454,7 +454,7 @@ const DrawerLayout = function DrawerLayout( ); const handleRelease = useCallback( - (event: PanGestureActiveEvent & { canceled: boolean }) => { + (event: PanGestureDeactivateEvent) => { 'worklet'; if (event.canceled) { // Settle the drawer where it rested before the gesture. diff --git a/packages/react-native-gesture-handler/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx b/packages/react-native-gesture-handler/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx index 458ba929b2..2b3789a527 100644 --- a/packages/react-native-gesture-handler/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +++ b/packages/react-native-gesture-handler/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx @@ -26,7 +26,10 @@ import { import { tagMessage } from '../../utils'; import { GestureDetector } from '../../v3/detectors'; -import type { PanGestureActiveEvent } from '../../v3/hooks/gestures'; +import type { + PanGestureActiveEvent, + PanGestureDeactivateEvent, +} from '../../v3/hooks/gestures'; import { usePanGesture, useTapGesture } from '../../v3/hooks/gestures'; import { maybeUnpackValue, @@ -507,7 +510,7 @@ const Swipeable = (props: SwipeableProps) => { ); const handleRelease = useCallback( - (event: PanGestureActiveEvent & { canceled: boolean }) => { + (event: PanGestureDeactivateEvent) => { 'worklet'; if (event.canceled) { // Restore the row to where it rested before the gesture. diff --git a/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx b/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx index 66fe341b79..30a9636aae 100644 --- a/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx +++ b/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx @@ -5,8 +5,12 @@ import { Animated, Platform, StyleSheet } from 'react-native'; import GestureHandlerButton from '../../components/GestureHandlerButton'; import { getTVProps } from '../../components/utils'; import createNativeWrapper from '../createNativeWrapper'; -import type { NativeHandlerData } from '../hooks/gestures/native/NativeTypes'; -import type { GestureEndEvent, GestureEvent } from '../types'; +import type { + NativeGestureActiveEvent, + NativeGestureBeginEvent, + NativeGestureDeactivateEvent, + NativeGestureFinalizeEvent, +} from '../hooks/gestures'; import type { BaseButtonProps, BorderlessButtonProps, @@ -14,9 +18,6 @@ import type { RectButtonProps, } from './GestureButtonsProps'; -type CallbackEventType = GestureEvent; -type EndCallbackEventType = GestureEndEvent; - type RawButtonInnerProps = RawButtonProps & { needsOffscreenAlphaCompositing?: boolean | undefined; }; @@ -54,7 +55,7 @@ export const BaseButton = (props: BaseButtonProps) => { onLongPress?.(); }; - const onBegin = (e: CallbackEventType) => { + const onBegin = (e: NativeGestureBeginEvent) => { if (!e.pointerInside) { return; } @@ -69,7 +70,7 @@ export const BaseButton = (props: BaseButtonProps) => { props.onBegin?.(e); }; - const onActivate = (e: CallbackEventType) => { + const onActivate = (e: NativeGestureActiveEvent) => { if (!e.pointerInside && longPressTimeout.current !== undefined) { clearTimeout(longPressTimeout.current); longPressTimeout.current = undefined; @@ -78,11 +79,11 @@ export const BaseButton = (props: BaseButtonProps) => { props.onActivate?.(e); }; - const onDeactivate = (e: EndCallbackEventType) => { + const onDeactivate = (e: NativeGestureDeactivateEvent) => { props.onDeactivate?.(e); }; - const onFinalize = (e: EndCallbackEventType) => { + const onFinalize = (e: NativeGestureFinalizeEvent) => { onActiveStateChange?.(false); if (!e.canceled && !longPressDetected.current) { diff --git a/packages/react-native-gesture-handler/src/v3/components/Touchable/TouchableProps.ts b/packages/react-native-gesture-handler/src/v3/components/Touchable/TouchableProps.ts index 27cab35029..5f95ac8ae0 100644 --- a/packages/react-native-gesture-handler/src/v3/components/Touchable/TouchableProps.ts +++ b/packages/react-native-gesture-handler/src/v3/components/Touchable/TouchableProps.ts @@ -4,13 +4,8 @@ import type { ButtonEvent, ButtonProps, } from '../../../components/GestureHandlerButton'; -import type { NativeHandlerData } from '../../hooks/gestures/native/NativeTypes'; -import type { GestureEndEvent, GestureEvent } from '../../types'; import type { BaseButtonProps, RawButtonProps } from '../GestureButtonsProps'; -export type CallbackEventType = GestureEvent; -export type EndCallbackEventType = GestureEndEvent; - type PressableAndroidRippleConfig = { [K in keyof RNPressableAndroidRippleConfig]?: Exclude< RNPressableAndroidRippleConfig[K], diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts index cf093c3afa..8632028e40 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts @@ -1,6 +1,7 @@ import type { BaseDiscreteGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, WithSharedValue, @@ -51,8 +52,12 @@ export type FlingGestureInternalConfig = BaseDiscreteGestureConfig< export type FlingGestureConfig = ExcludeInternalConfigProps; -export type FlingGestureEvent = GestureEvent; -export type FlingGestureActiveEvent = FlingGestureEvent; +export type FlingGestureBeginEvent = GestureEvent; +export type FlingGestureActiveEvent = FlingGestureBeginEvent; +export type FlingGestureDeactivateEvent = GestureEndEvent; +export type FlingGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `FlingGestureBeginEvent` instead. */ +export type FlingGestureEvent = FlingGestureBeginEvent; export type FlingGesture = SingleGesture< FlingGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts index a2f74a115a..f42fba10da 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts @@ -3,6 +3,7 @@ import type { HoverEffect } from '../../../../HoverEffect'; import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, WithSharedValue, @@ -66,8 +67,13 @@ export type HoverGestureInternalConfig = BaseGestureConfig< HoverExtendedHandlerData >; -export type HoverGestureEvent = GestureEvent; +export type HoverGestureBeginEvent = GestureEvent; export type HoverGestureActiveEvent = GestureEvent; +export type HoverGestureDeactivateEvent = + GestureEndEvent; +export type HoverGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `HoverGestureBeginEvent` instead. */ +export type HoverGestureEvent = HoverGestureBeginEvent; export type HoverGesture = SingleGesture< HoverGestureInternalProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts index ca6c7fd015..465a1ffe9c 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts @@ -1,127 +1,181 @@ import type { FlingGesture, FlingGestureActiveEvent, + FlingGestureBeginEvent, FlingGestureConfig, + FlingGestureDeactivateEvent, FlingGestureEvent, + FlingGestureFinalizeEvent, } from './fling/FlingTypes'; import type { HoverGesture, HoverGestureActiveEvent, + HoverGestureBeginEvent, HoverGestureConfig, + HoverGestureDeactivateEvent, HoverGestureEvent, + HoverGestureFinalizeEvent, } from './hover/HoverTypes'; import type { LongPressGesture, LongPressGestureActiveEvent, + LongPressGestureBeginEvent, LongPressGestureConfig, + LongPressGestureDeactivateEvent, LongPressGestureEvent, + LongPressGestureFinalizeEvent, } from './longPress/LongPressTypes'; import type { ManualGesture, ManualGestureActiveEvent, + ManualGestureBeginEvent, ManualGestureConfig, + ManualGestureDeactivateEvent, ManualGestureEvent, + ManualGestureFinalizeEvent, } from './manual/ManualTypes'; import type { NativeGesture, NativeGestureActiveEvent, + NativeGestureBeginEvent, NativeGestureConfig, + NativeGestureDeactivateEvent, NativeGestureEvent, + NativeGestureFinalizeEvent, } from './native/NativeTypes'; import type { PanGesture, PanGestureActiveEvent, + PanGestureBeginEvent, PanGestureConfig, + PanGestureDeactivateEvent, PanGestureEvent, + PanGestureFinalizeEvent, } from './pan/PanTypes'; import type { PinchGesture, PinchGestureActiveEvent, + PinchGestureBeginEvent, PinchGestureConfig, + PinchGestureDeactivateEvent, PinchGestureEvent, + PinchGestureFinalizeEvent, } from './pinch/PinchTypes'; import type { RotationGesture, RotationGestureActiveEvent, + RotationGestureBeginEvent, RotationGestureConfig, + RotationGestureDeactivateEvent, RotationGestureEvent, + RotationGestureFinalizeEvent, } from './rotation/RotationTypes'; import type { TapGesture, TapGestureActiveEvent, + TapGestureBeginEvent, TapGestureConfig, + TapGestureDeactivateEvent, TapGestureEvent, + TapGestureFinalizeEvent, } from './tap/TapTypes'; export type { TapGesture, TapGestureActiveEvent, + TapGestureBeginEvent, TapGestureConfig, + TapGestureDeactivateEvent, TapGestureEvent, + TapGestureFinalizeEvent, }; export { useTapGesture } from './tap/useTapGesture'; export type { FlingGesture, FlingGestureActiveEvent, + FlingGestureBeginEvent, FlingGestureConfig, + FlingGestureDeactivateEvent, FlingGestureEvent, + FlingGestureFinalizeEvent, }; export { useFlingGesture } from './fling/useFlingGesture'; export type { LongPressGesture, LongPressGestureActiveEvent, + LongPressGestureBeginEvent, LongPressGestureConfig, + LongPressGestureDeactivateEvent, LongPressGestureEvent, + LongPressGestureFinalizeEvent, }; export { useLongPressGesture } from './longPress/useLongPressGesture'; export type { PinchGesture, PinchGestureActiveEvent, + PinchGestureBeginEvent, PinchGestureConfig, + PinchGestureDeactivateEvent, PinchGestureEvent, + PinchGestureFinalizeEvent, }; export { usePinchGesture } from './pinch/usePinchGesture'; export type { RotationGesture, RotationGestureActiveEvent, + RotationGestureBeginEvent, RotationGestureConfig, + RotationGestureDeactivateEvent, RotationGestureEvent, + RotationGestureFinalizeEvent, }; export { useRotationGesture } from './rotation/useRotationGesture'; export type { HoverGesture, HoverGestureActiveEvent, + HoverGestureBeginEvent, HoverGestureConfig, + HoverGestureDeactivateEvent, HoverGestureEvent, + HoverGestureFinalizeEvent, }; export { useHoverGesture } from './hover/useHoverGesture'; export type { ManualGesture, ManualGestureActiveEvent, + ManualGestureBeginEvent, ManualGestureConfig, + ManualGestureDeactivateEvent, ManualGestureEvent, + ManualGestureFinalizeEvent, }; export { useManualGesture } from './manual/useManualGesture'; export type { NativeGesture, NativeGestureActiveEvent, + NativeGestureBeginEvent, NativeGestureConfig, + NativeGestureDeactivateEvent, NativeGestureEvent, + NativeGestureFinalizeEvent, }; export { useNativeGesture } from './native/useNativeGesture'; export type { PanGesture, PanGestureActiveEvent, + PanGestureBeginEvent, PanGestureConfig, + PanGestureDeactivateEvent, PanGestureEvent, + PanGestureFinalizeEvent, }; export { usePanGesture } from './pan/usePanGesture'; @@ -138,20 +192,40 @@ export type SingleGesture = /* eslint-disable @typescript-eslint/no-duplicate-type-constituents */ export type SingleGestureEvent = - | TapGestureEvent + | TapGestureBeginEvent | TapGestureActiveEvent - | FlingGestureEvent + | TapGestureDeactivateEvent + | TapGestureFinalizeEvent + | FlingGestureBeginEvent | FlingGestureActiveEvent - | LongPressGestureEvent + | FlingGestureDeactivateEvent + | FlingGestureFinalizeEvent + | LongPressGestureBeginEvent | LongPressGestureActiveEvent - | RotationGestureEvent + | LongPressGestureDeactivateEvent + | LongPressGestureFinalizeEvent + | PinchGestureBeginEvent + | PinchGestureActiveEvent + | PinchGestureDeactivateEvent + | PinchGestureFinalizeEvent + | RotationGestureBeginEvent | RotationGestureActiveEvent - | HoverGestureEvent + | RotationGestureDeactivateEvent + | RotationGestureFinalizeEvent + | HoverGestureBeginEvent | HoverGestureActiveEvent - | ManualGestureEvent + | HoverGestureDeactivateEvent + | HoverGestureFinalizeEvent + | ManualGestureBeginEvent | ManualGestureActiveEvent - | NativeGestureEvent + | ManualGestureDeactivateEvent + | ManualGestureFinalizeEvent + | NativeGestureBeginEvent | NativeGestureActiveEvent - | PanGestureEvent - | PanGestureActiveEvent; + | NativeGestureDeactivateEvent + | NativeGestureFinalizeEvent + | PanGestureBeginEvent + | PanGestureActiveEvent + | PanGestureDeactivateEvent + | PanGestureFinalizeEvent; /* eslint-enable @typescript-eslint/no-duplicate-type-constituents */ diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts index 5736206cf7..764835af11 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts @@ -1,6 +1,7 @@ import type { BaseDiscreteGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, WithSharedValue, @@ -63,8 +64,14 @@ export type LongPressGestureInternalConfig = BaseDiscreteGestureConfig< LongPressHandlerData >; -export type LongPressGestureEvent = GestureEvent; -export type LongPressGestureActiveEvent = LongPressGestureEvent; +export type LongPressGestureBeginEvent = GestureEvent; +export type LongPressGestureActiveEvent = LongPressGestureBeginEvent; +export type LongPressGestureDeactivateEvent = + GestureEndEvent; +export type LongPressGestureFinalizeEvent = + GestureEndEvent; +/** @deprecated Use `LongPressGestureBeginEvent` instead. */ +export type LongPressGestureEvent = LongPressGestureBeginEvent; export type LongPressGesture = SingleGesture< LongPressGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts index 81946bcac7..663fe92fd7 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts @@ -1,6 +1,7 @@ import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, } from '../../../types'; @@ -19,8 +20,12 @@ export type ManualGestureInternalConfig = BaseGestureConfig< export type ManualGestureConfig = ExcludeInternalConfigProps; -export type ManualGestureEvent = GestureEvent; -export type ManualGestureActiveEvent = ManualGestureEvent; +export type ManualGestureBeginEvent = GestureEvent; +export type ManualGestureActiveEvent = ManualGestureBeginEvent; +export type ManualGestureDeactivateEvent = GestureEndEvent; +export type ManualGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `ManualGestureBeginEvent` instead. */ +export type ManualGestureEvent = ManualGestureBeginEvent; export type ManualGesture = SingleGesture< ManualGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts index be0d4b4305..d8fd48bd84 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts @@ -1,6 +1,7 @@ import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, WithSharedValue, @@ -73,8 +74,12 @@ export type NativeGestureInternalConfig = BaseGestureConfig< export type NativeGestureConfig = ExcludeInternalConfigProps; -export type NativeGestureEvent = GestureEvent; -export type NativeGestureActiveEvent = NativeGestureEvent; +export type NativeGestureBeginEvent = GestureEvent; +export type NativeGestureActiveEvent = NativeGestureBeginEvent; +export type NativeGestureDeactivateEvent = GestureEndEvent; +export type NativeGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `NativeGestureBeginEvent` instead. */ +export type NativeGestureEvent = NativeGestureBeginEvent; export type NativeGesture = SingleGesture< NativeGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts index 86a859c42f..83ab4606bf 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts @@ -2,6 +2,7 @@ import type { StylusData } from '../../../../handlers/gestureHandlerCommon'; import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, WithSharedValue, @@ -179,8 +180,12 @@ export type PanGestureInternalConfig = BaseGestureConfig< PanExtendedHandlerData >; -export type PanGestureEvent = GestureEvent; +export type PanGestureBeginEvent = GestureEvent; export type PanGestureActiveEvent = GestureEvent; +export type PanGestureDeactivateEvent = GestureEndEvent; +export type PanGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `PanGestureBeginEvent` instead. */ +export type PanGestureEvent = PanGestureBeginEvent; export type PanGesture = SingleGesture< PanGestureInternalProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts index e6b7aa9877..5c14818f22 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts @@ -1,6 +1,7 @@ import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, } from '../../../types'; @@ -30,8 +31,13 @@ export type PinchGestureInternalConfig = BaseGestureConfig< export type PinchGestureConfig = ExcludeInternalConfigProps; -export type PinchGestureEvent = GestureEvent; +export type PinchGestureBeginEvent = GestureEvent; export type PinchGestureActiveEvent = GestureEvent; +export type PinchGestureDeactivateEvent = + GestureEndEvent; +export type PinchGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `PinchGestureBeginEvent` instead. */ +export type PinchGestureEvent = PinchGestureBeginEvent; export type PinchGesture = SingleGesture< PinchGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts index 9327ca1d67..2966b1594e 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts @@ -1,6 +1,7 @@ import type { BaseGestureConfig, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, SingleGesture, } from '../../../types'; @@ -30,9 +31,14 @@ export type RotationGestureInternalConfig = BaseGestureConfig< export type RotationGestureConfig = ExcludeInternalConfigProps; -export type RotationGestureEvent = GestureEvent; +export type RotationGestureBeginEvent = GestureEvent; export type RotationGestureActiveEvent = GestureEvent; +export type RotationGestureDeactivateEvent = + GestureEndEvent; +export type RotationGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `RotationGestureBeginEvent` instead. */ +export type RotationGestureEvent = RotationGestureBeginEvent; export type RotationGesture = SingleGesture< RotationGestureProperties, diff --git a/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts b/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts index 9ba4844979..03c7f13e86 100644 --- a/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts @@ -2,6 +2,7 @@ import type { BaseDiscreteGestureConfig, DiscreteSingleGesture, ExcludeInternalConfigProps, + GestureEndEvent, GestureEvent, WithSharedValue, } from '../../../types'; @@ -96,8 +97,12 @@ export type TapGestureInternalConfig = BaseDiscreteGestureConfig< TapHandlerData >; -export type TapGestureEvent = GestureEvent; -export type TapGestureActiveEvent = TapGestureEvent; +export type TapGestureBeginEvent = GestureEvent; +export type TapGestureActiveEvent = TapGestureBeginEvent; +export type TapGestureDeactivateEvent = GestureEndEvent; +export type TapGestureFinalizeEvent = GestureEndEvent; +/** @deprecated Use `TapGestureBeginEvent` instead. */ +export type TapGestureEvent = TapGestureBeginEvent; export type TapGesture = DiscreteSingleGesture< TapGestureInternalProperties, diff --git a/packages/react-native-gesture-handler/src/v3/index.ts b/packages/react-native-gesture-handler/src/v3/index.ts index d226128862..9fbbcfc464 100644 --- a/packages/react-native-gesture-handler/src/v3/index.ts +++ b/packages/react-native-gesture-handler/src/v3/index.ts @@ -29,42 +29,69 @@ export { GestureStateManager } from './gestureStateManager'; export type { FlingGesture, FlingGestureActiveEvent, + FlingGestureBeginEvent, FlingGestureConfig, + FlingGestureDeactivateEvent, FlingGestureEvent, + FlingGestureFinalizeEvent, HoverGesture, HoverGestureActiveEvent, + HoverGestureBeginEvent, HoverGestureConfig, + HoverGestureDeactivateEvent, HoverGestureEvent, + HoverGestureFinalizeEvent, LongPressGesture, LongPressGestureActiveEvent, + LongPressGestureBeginEvent, LongPressGestureConfig, + LongPressGestureDeactivateEvent, LongPressGestureEvent, + LongPressGestureFinalizeEvent, ManualGesture, ManualGestureActiveEvent, + ManualGestureBeginEvent, ManualGestureConfig, + ManualGestureDeactivateEvent, ManualGestureEvent, + ManualGestureFinalizeEvent, NativeGesture, NativeGestureActiveEvent, + NativeGestureBeginEvent, NativeGestureConfig, + NativeGestureDeactivateEvent, NativeGestureEvent, + NativeGestureFinalizeEvent, PanGesture, PanGestureActiveEvent, + PanGestureBeginEvent, PanGestureConfig, + PanGestureDeactivateEvent, PanGestureEvent, + PanGestureFinalizeEvent, PinchGesture, PinchGestureActiveEvent, + PinchGestureBeginEvent, PinchGestureConfig, + PinchGestureDeactivateEvent, PinchGestureEvent, + PinchGestureFinalizeEvent, RotationGesture, RotationGestureActiveEvent, + RotationGestureBeginEvent, RotationGestureConfig, + RotationGestureDeactivateEvent, RotationGestureEvent, + RotationGestureFinalizeEvent, SingleGesture, SingleGestureEvent, TapGesture, TapGestureActiveEvent, + TapGestureBeginEvent, TapGestureConfig, + TapGestureDeactivateEvent, TapGestureEvent, + TapGestureFinalizeEvent, } from './hooks'; export { useCompetingGestures,