Skip to content

[Web] Fix view relative coordinates of trackpad pan events - #4531

Open
giaBaoJS wants to merge 1 commit into
software-mansion:mainfrom
giaBaoJS:web-wheel-relative-coords
Open

giaBaoJS wants to merge 1 commit into
software-mansion:mainfrom
giaBaoJS:web-wheel-relative-coords

Conversation

@giaBaoJS

Copy link
Copy Markdown
Contributor

Description

WheelEventManager synthesizes a moving pointer out of a stationary cursor by accumulating wheel deltas, but only the page coordinates use the accumulator:

this.wheelDelta.x += event.deltaX;      // wheelCallback

x: event.clientX + this.wheelDelta.x,   // accumulated
offsetX: event.offsetX - event.deltaX,  // one event, opposite sign

Repro: a Pan with enableTrackpadTwoFingerGesture on web, three trackpad frames of deltaY: 10 from clientY: 0, offsetY: 0. absoluteY reads 10, 20, 30 while y reads -10, -10, -10. y points the wrong way and never advances for the whole gesture. translationY, velocityY and absoluteY are fine, they come off the page coordinates.

x/y and absoluteX/absoluteY are the same point in two spaces, so they can only differ by the view's page offset. Every other producer keeps that invariant: PointerEventManager.ts:230 derives offsetX from the same clientX it writes to x, KeyboardEventManager.ts:120-129 writes the view centre into both, ScrollEventManager.ts:31-34 writes one value twice, and GestureHandlerButton.web.tsx:51-53 computes x from absoluteX. WheelEventManager.ts:35-36 is the only place where the two move apart.

The fix applies the same accumulator to both. onWheel is overridden only by PanGestureHandler, and the wheel offsetX/offsetY reaches exactly one consumer, PointerTracker.relativeCoords -> GestureHandler.transformNativeEvent():759.

Boundary: the base stays event.offsetX, which is relative to event.target rather than to the handler's view, so a wheel over a child element is still off by that child's position. PointerEventManager sidesteps that with (clientX - rect.left) / scaleX, but doing the same here costs a getBoundingClientRect per wheel event, which ScrollEventManager.mapEvent explicitly declines to pay. Left as a separate question.

Test plan

yarn workspace react-native-gesture-handler test - 179 passed, was 178.

The new PanGestureHandler trackpad coordinates case drives the real WheelEventManager off a fake view and asserts the two spaces agree for a view at the page origin. On main it reports x: -5, y: -10 against absoluteX: 15, absoluteY: 30.

ts-check, lint-js and circular-dependency-check are clean.

`WheelEventManager` synthesizes a moving pointer from a stationary cursor
by accumulating wheel deltas, but only the page coordinates used the
accumulator. The view relative ones subtracted a single event's delta, so
they moved opposite to the page ones and never advanced across a gesture.
Copilot AI lite review requested due to automatic review settings September 20, 2026 09:01
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 02622e14-eabd-480a-8f3d-23e665e38c12

📥 Commits

Reviewing files that changed from the base of the PR and between 4c001cb and ad0de17.

📒 Files selected for processing (2)
  • packages/react-native-gesture-handler/src/web/handlers/__tests__/PanGestureHandler.test.ts
  • packages/react-native-gesture-handler/src/web/tools/WheelEventManager.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved trackpad gesture coordinate handling on web.
    • Corrected horizontal and vertical offset calculations when wheel movement is combined with pointer movement.
    • Ensured view-relative coordinates remain consistent with page coordinates.

Walkthrough

Wheel-event coordinate mapping now uses accumulated deltas for transformed offsets. Tests add horizontal wheel input and verify accumulated view-relative and page coordinates.

Changes

Wheel coordinate mapping

Layer / File(s) Summary
Accumulated wheel coordinate mapping
packages/react-native-gesture-handler/src/web/tools/WheelEventManager.ts
mapEvent now adds accumulated wheel deltas to the raw horizontal and vertical offsets.
Trackpad coordinate regression coverage
packages/react-native-gesture-handler/src/web/handlers/__tests__/PanGestureHandler.test.ts
TestPanGestureHandler exposes the transformed native event. FakeView.wheel forwards an optional horizontal delta. Tests verify accumulated trackpad coordinates on both axes.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing view-relative coordinates for web trackpad pan events.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Copilot review overview

🟢 Approval recommended

The fix is localized, consistent with existing coordinate handling, and covered by regression tests.

Review effort: Lite
Findings: None

What changed in this PR

Fixes web trackpad pan coordinates so relative x/y advance consistently with absolute coordinates.

Changes:

  • Applies accumulated wheel deltas to offsetX and offsetY.
  • Adds regression coverage for trackpad coordinate consistency.
File Description
WheelEventManager.ts Corrects accumulated relative wheel coordinates.
PanGestureHandler.test.ts Adds trackpad coordinate regression tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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