Skip to content

Adds recognizer-backed Jest gesture simulation for v3 gestures and relations.#4312

Closed
coado wants to merge 3 commits into
mainfrom
@coado/jest-new-api-2
Closed

Adds recognizer-backed Jest gesture simulation for v3 gestures and relations.#4312
coado wants to merge 3 commits into
mainfrom
@coado/jest-new-api-2

Conversation

@coado

@coado coado commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

The fireGesture feeds deterministic pointer input into web gesture recognizers, then routes their state requests through GestureArbitrator. This lets tests cover real recognition outcomes and composed relations without manually supplying RNGH states.

fireGesture(
  useCompetingGestures(tap, pan),
  swipe({
    from: { x: 0, y: 0 },
    to: { x: 100, y: 0 },
    steps: 4,
  })
);

expect(onPanActivate).toHaveBeenCalled();
expect(onTapActivate).not.toHaveBeenCalled();

or with other helpers:

fireGesture(tapGesture, tap({ at: { x: 20, y: 40 } }));

fireGesture(
  longPressGesture,
  longPress({ at: { x: 20, y: 40 }, duration: 500 }),
  { advanceTimers: jest.advanceTimersByTime }
);

fireGesture(
  pinchGesture,
  pinch({
    from: [{ x: 0, y: 0 }, { x: 0, y: 40 }],
    to: [{ x: 0, y: 0 }, { x: 0, y: 100 }],
  })
);

The API includes low-level composable primitives (pointerSequence, multiPointerSequence) and convenience helpers (tap, doubleTap, longPress, swipe, pinch, rotate). Also extracts the shared relation/state policy into GestureArbitrator, leaving web-specific pointer-overlap behavior in GestureHandlerOrchestrator.

Test plan

Added new tests.

Copilot AI review requested due to automatic review settings July 13, 2026 09:38

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 adds a recognizer-backed Jest gesture simulation API for v3 gestures on web by feeding deterministic pointer input into the existing web recognizers and routing competing/simultaneous state transitions through a newly extracted GestureArbitrator (so tests can validate real recognition outcomes + relations without manually crafting RNGH state events).

Changes:

  • Extract shared relation/state arbitration logic into GestureArbitrator, leaving web-specific pointer-overlap conflict detection in GestureHandlerOrchestrator.
  • Add new Jest utilities: fireGesture, pointer-gesture builders (tap, swipe, pinch, rotate, etc.), and a createGestureController state-machine driver.
  • Refactor web handlers to allow injecting an orchestrator + interaction manager for isolated (non-singleton) Jest sessions; add new tests for the helpers.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/react-native-gesture-handler/src/web/tools/InteractionManager.ts Makes interaction relations configurable per isolated session (no longer constructor-locked to singleton).
packages/react-native-gesture-handler/src/web/tools/GestureHandlerOrchestrator.ts Becomes a web adapter delegating shared arbitration to GestureArbitrator.
packages/react-native-gesture-handler/src/web/tools/GestureArbitrator.ts New shared arbitration engine for handler state observability across relations.
packages/react-native-gesture-handler/src/web/handlers/IGestureHandler.ts Adds injection hooks for orchestrator + interaction manager to support isolated sessions.
packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts Stores injected orchestrator/interaction manager and uses them instead of global singletons.
packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts Adds createGestureController, fireGesture, and pointer gesture primitives/helpers.
packages/react-native-gesture-handler/src/jestUtils/index.ts Re-exports the new Jest helper APIs and types.
packages/react-native-gesture-handler/src/tests/gestureController.test.tsx Adds Jest coverage for controller lifecycle and recognizer-backed pointer simulations + relations.

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

Comment on lines +1169 to +1174
invariant(
pointerGesture.steps.length > 0,
'fireGesture requires pointer input. Use tap(), swipe(), or pointerSequence().'
);

let time = 0;
Comment on lines +1203 to +1211
if (step.type === 'wait') {
invariant(
advanceTimers !== undefined,
'fireGesture needs advanceTimers to process waits. Pass jest.advanceTimersByTime as the third argument.'
);
advanceTimers(step.duration);
time += step.duration;
return;
}
@coado coado closed this Jul 14, 2026
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