Skip to content

Extract a platform-neutral gesture arbitration core#4300

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

Extract a platform-neutral gesture arbitration core#4300
coado wants to merge 4 commits into
mainfrom
@coado/jest-tests-2

Conversation

@coado

@coado coado commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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

Copilot AI review requested due to automatic review settings July 6, 2026 16:02

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 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 + GestureRelationPolicy as 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 type discriminant through SingleGesture/DiscreteSingleGesture, plus adds a concrete AnySingleGesture union 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
)
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