Preserve literal SingleGestureName in v3 gesture types#4299
Draft
coado wants to merge 2 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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 SingleGestureNametype parameter toSingleGestureandDiscreteSingleGesture, and thread it throughuseGesture. - Update concrete gesture types (Tap/Pan/Pinch/Rotation/etc.) to bind
typeto their specificSingleGestureName.*member. - Introduce
AnySingleGestureas 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'; | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Makes SingleGesture/DiscreteSingleGesture generic over their
SingleGestureNameliteral 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