Extract a platform-neutral gesture arbitration core#4300
Draft
coado wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extracts the web GestureHandlerOrchestrator’s state/arbitration logic into a new, platform-neutral GestureArbitrator core that operates via an injected relation policy, and updates v3 gesture typing to preserve a discriminated type for better narrowing in tests and tooling.
Changes:
- Introduces
GestureArbitrator+GestureRelationPolicyas a reusable, platform-neutral arbitration core. - Refactors the web orchestrator into a thin adapter that supplies a web-specific relation policy and delegates arbitration to the core.
- Improves v3 gesture typings by threading a concrete
typediscriminant throughSingleGesture/DiscreteSingleGesture, plus adds a concreteAnySingleGestureunion used by the test registry.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/web/tools/GestureHandlerOrchestrator.ts | Replaced in-file arbitration with a web policy + delegation to GestureArbitrator. |
| packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrator.ts | New platform-neutral arbitration engine extracted from the web orchestrator. |
| packages/react-native-gesture-handler/src/handlers/gestureArbitration/GestureArbitrationTypes.ts | New platform-neutral handler contract and injected relation-policy interface. |
| packages/react-native-gesture-handler/src/tests/GestureHandlerOrchestrator.test.ts | Adds Jest characterization tests for orchestrator/arbitration behavior. |
| packages/react-native-gesture-handler/src/handlers/handlersRegistry.ts | Stores test-registered v3 gestures as a concrete union for type narrowing. |
| packages/react-native-gesture-handler/src/v3/types/GestureTypes.ts | Adds a TType generic so SingleGesture.type can remain discriminated. |
| packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts | Threads TType through useGesture to preserve the discriminant in returns. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/useTapGesture.ts | Updates explicit generics so returned gesture keeps type = Tap. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/tap/TapTypes.ts | Specializes TapGesture to SingleGestureName.Tap. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPressGesture.ts | Updates explicit generics so returned gesture keeps type = LongPress. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/LongPressTypes.ts | Specializes LongPressGesture to SingleGestureName.LongPress. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePanGesture.ts | Updates explicit generics so returned gesture keeps type = Pan. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/PanTypes.ts | Specializes PanGesture to SingleGestureName.Pan. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/pinch/PinchTypes.ts | Specializes PinchGesture to SingleGestureName.Pinch. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/rotation/RotationTypes.ts | Specializes RotationGesture to SingleGestureName.Rotation. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/FlingTypes.ts | Specializes FlingGesture to SingleGestureName.Fling. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/HoverTypes.ts | Specializes HoverGesture to SingleGestureName.Hover. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/ManualTypes.ts | Specializes ManualGesture to SingleGestureName.Manual. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/native/NativeTypes.ts | Specializes NativeGesture to SingleGestureName.Native. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/singleGestureUnion.ts | Adds AnySingleGesture union of concrete gesture types for narrowing. |
| packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts | Re-exports the new union and preserves SingleGesture alias from hooks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const shouldBeCancelledBy = (otherHandler: IGestureHandler) => { | ||
| return this.shouldHandlerBeCancelledBy(handler, otherHandler); | ||
| }; | ||
| // Private beacuse of Singleton |
Comment on lines
+60
to
+63
| shouldBeginWithRecordedHandlers: (handler, recordedHandlers) => | ||
| handler.shouldBeginWithRecordedHandlers( | ||
| recordedHandlers as IGestureHandler[] | ||
| ), |
Comment on lines
+27
to
+29
| public get recordedHandlers(): readonly THandler[] { | ||
| return this.gestureHandlers; | ||
| } |
Comment on lines
+290
to
+294
| if ( | ||
| !this.relationPolicy.shouldBeginWithRecordedHandlers( | ||
| handler, | ||
| this.gestureHandlers | ||
| ) |
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
Extract the relation-independent state/arbitration logic out of the web GestureHandlerOrchestrator into a shared, platform-neutral core with an injected relation policy. No behavior change — the web orchestrator becomes a thin adapter that supplies web-only policy (shared pointers, view overlap, native-view rules) and delegates all arbitration to the core. This is what the Jest testing API will reuse so transition rules don't drift.
Test plan
yarn test