Add recognizer-aware Jest API#4307
Draft
coado wants to merge 5 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an experimental, recognizer-aware Jest gesture simulation helper for feeding synthetic pointer streams through real web/JS recognizers, and refactors the web orchestrator’s state arbitration into a shared, policy-driven core to support that path.
Changes:
- Introduces
simulatePointerGestureto drive real web gesture handlers in Jest (including resolving targets via v3 gestures, test IDs, and detector hosts). - Extracts platform-neutral arbitration logic into
GestureArbitratorand updates the webGestureHandlerOrchestratorto delegate to it. - Improves v3 gesture typing (discriminated
type) and centralizes the single-gesture union type.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/web/tools/GestureHandlerOrchestrator.ts | Delegates orchestration/arbitration to the new shared GestureArbitrator with a web relation policy. |
| packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts | Adds a generic TType to make SingleGesture.type discriminated. |
| packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts | Propagates the discriminated gesture type through useGesture generics. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTapGesture.ts | Specializes useGesture generics so Tap gestures narrow their type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts | Updates Tap gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/singleGestureUnion.ts | Introduces a shared AnySingleGesture union type for v3 single gestures. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts | Updates Rotation gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts | Updates Pinch gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePanGesture.ts | Specializes useGesture generics so Pan gestures narrow their type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts | Updates Pan gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts | Updates Native gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts | Updates Manual gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPressGesture.ts | Specializes useGesture generics so LongPress gestures narrow their type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts | Updates LongPress gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts | Re-exports the consolidated single-gesture union type from singleGestureUnion.ts. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts | Updates Hover gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts | Updates Fling gesture type aliases to carry the discriminated type. |
| packages/react-native-gesture-handler/src/mocks/hostDetector.tsx | Enhances the Jest host detector mock typing to include handlerTags for detector-based resolution. |
| packages/react-native-gesture-handler/src/jestUtils/simulatePointerGesture.ts | Adds the new recognizer-aware pointer gesture simulation utility for Jest. |
| packages/react-native-gesture-handler/src/jestUtils/index.ts | Exposes simulatePointerGesture and its options from the Jest utils barrel. |
| packages/react-native-gesture-handler/src/handlers/handlersRegistry.ts | Stores v3 hook gestures in test env to enable detector/testID resolution and narrowing. |
| packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrator.ts | Adds the platform-neutral arbitration core (record/await/activate/cancel sequencing). |
| packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrationTypes.ts | Defines the platform-neutral handler and relation-policy contracts. |
| packages/react-native-gesture-handler/src/tests/recognizerAwareGesture.test.tsx | Adds Jest tests covering the new pointer simulation API and target resolution behaviors. |
| packages/react-native-gesture-handler/src/tests/GestureHandlerOrchestrator.test.ts | Adds characterization tests for orchestrator/arbitration behavior (awaiting, cancellation, simultaneity). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+359
to
+369
| return pointers.map((pointer, index) => { | ||
| invariant( | ||
| pointer.path.length > 0, | ||
| 'simulatePointerGesture() expected each pointer path to contain at least one point.' | ||
| ); | ||
|
|
||
| return { | ||
| id: pointer.id ?? index + 1, | ||
| path: pointer.path, | ||
| }; | ||
| }); |
Comment on lines
+60
to
+63
| shouldBeginWithRecordedHandlers: (handler, recordedHandlers) => | ||
| handler.shouldBeginWithRecordedHandlers( | ||
| recordedHandlers as IGestureHandler[] | ||
| ), |
| const shouldBeCancelledBy = (otherHandler: IGestureHandler) => { | ||
| return this.shouldHandlerBeCancelledBy(handler, otherHandler); | ||
| }; | ||
| // Private beacuse of Singleton |
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
Adds an experimental recognizer-aware Jest gesture simulation API:
simulatePointerGesturefor feeding fake pointer streams into real JS/web recognizers instead of manually emitting gesture states,Tap,Pan,LongPress,Fling,Pinch, andRotationrecognizers,timeStepMs, hold timing viaholdForMs, and multi-pointer paths via pointers,Test plan
Added new tests