Repository navigation
Commit 613be1c
authored
[Web] Report zero Pan velocity when the pointer rested before release (#4641)
## Description
On web, `PanGestureHandler.onPointerUp` ends the gesture without looking
at the release event, so `onEnd` carries the velocity computed by the
last `pointermove`, however long ago that was. A drag that stops, holds
still, and then releases reports the velocity of the drag, and a
`withDecay` started from it flings a pointer that had come to rest.
Android reports 0 in that case: its `VelocityTracker` treats a pointer
as stopped after 40 ms without a sample, [matching
Flutter](https://github.com/flutter/flutter/blob/66b3ad90177ccbd2963836a5556076b370622fe4/packages/flutter/lib/src/gestures/velocity_tracker.dart#L142).
The web `VelocityTracker` already uses the same 40 ms threshold to split
the sample history during a drag. The constant is now exported as
`POINTER_STOPPED_MILLISECONDS`, `PointerTracker.track` stamps the time
of each pointer's last sample, and `PointerTracker.getVelocityAt`
returns zero when the queried time is past that threshold. `onPointerUp`
reads the velocity at the release time before ending. A release within
40 ms of the last move is unchanged.
Feeding the release event into the tracker as a sample, as Android does,
was tried first and dropped: a release landing a few ms after the last
move at the same spot bent the least-squares fit and halved the reported
velocity of an ordinary fling.
Fixes #4636
## Test plan
Tested on the "Velocity Test" example.
- Two tests in `src/web/handlers/__tests__/PanGestureHandler.test.ts`: a
release at the last move keeps the drag's velocity, a release 500 ms
later reports zero. The second fails without the fix.
- Chrome, v3 `usePanGesture` screen with the reporter's drag (160 px in
48 ms) driven over CDP: released at the last move `velocityX` 3263
before and after; released 511 ms later 2707 before, 0 after.1 parent 4733795 commit 613be1c
4 files changed
Lines changed: 68 additions & 2 deletions
File tree
- packages/react-native-gesture-handler/src/web
- handlers
- __tests__
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
95 | 106 | | |
96 | 107 | | |
97 | 108 | | |
| |||
0 commit comments