Skip to content

Preserve literal SingleGestureName in v3 gesture types#4299

Draft
coado wants to merge 2 commits into
mainfrom
@coado/jest-tests-1
Draft

Preserve literal SingleGestureName in v3 gesture types#4299
coado wants to merge 2 commits into
mainfrom
@coado/jest-tests-1

Conversation

@coado

@coado coado commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Makes SingleGesture/DiscreteSingleGesture generic over their SingleGestureName literal so each concrete gesture is a discriminated-union member. This is a prerequisite for inferring gesture scenarios from a target, and is a standalone typing improvement.

Test plan

type changes only

Copilot AI review requested due to automatic review settings July 6, 2026 15:56
@coado coado changed the title @coado/jest tests 1 Preserve literal SingleGestureName in v3 gesture types Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves v3 gesture typing by making SingleGesture/DiscreteSingleGesture generic over their SingleGestureName discriminant, enabling concrete gestures to participate as discriminated-union members (useful for narrowing by gesture.type, including in test utilities).

Changes:

  • Add a TType extends SingleGestureName type parameter to SingleGesture and DiscreteSingleGesture, and thread it through useGesture.
  • Update concrete gesture types (Tap/Pan/Pinch/Rotation/etc.) to bind type to their specific SingleGestureName.* member.
  • Introduce AnySingleGesture as the union of concrete v3 single-gesture types and use it for test-ID lookups in the handler registry.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts Makes SingleGesture/DiscreteSingleGesture generic over the type discriminant.
packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts Propagates the gesture-name literal type through useGesture input/output.
packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTapGesture.ts Ensures tap hook returns a gesture with type: SingleGestureName.Tap.
packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts Binds TapGesture’s discriminant to SingleGestureName.Tap.
packages/react-native-gesture-handler/src/v3/hooks/gestures/singleGestureUnion.ts Adds AnySingleGesture union of concrete v3 single-gesture types.
packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts Binds RotationGesture’s discriminant to SingleGestureName.Rotation.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts Binds PinchGesture’s discriminant to SingleGestureName.Pinch.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePanGesture.ts Ensures pan hook returns a gesture with type: SingleGestureName.Pan.
packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts Binds PanGesture’s discriminant to SingleGestureName.Pan.
packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts Binds NativeGesture’s discriminant to SingleGestureName.Native.
packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts Binds ManualGesture’s discriminant to SingleGestureName.Manual.
packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPressGesture.ts Ensures long-press hook returns a gesture with type: SingleGestureName.LongPress.
packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts Binds LongPressGesture’s discriminant to SingleGestureName.LongPress.
packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts Re-exports AnySingleGesture and aliases it as the gestures-module SingleGesture union.
packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts Binds HoverGesture’s discriminant to SingleGestureName.Hover.
packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts Binds FlingGesture’s discriminant to SingleGestureName.Fling.
packages/react-native-gesture-handler/src/handlers/handlersRegistry.ts Stores v3 hook gestures (in test env) as a discriminated union to enable narrowing by type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,4 +1,5 @@
import { isTestEnv } from '../utils';
import type { AnySingleGesture } from '../v3/hooks/gestures/singleGestureUnion';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants