Repository navigation
Commit 2202d7b
[Web] Handle moves that leave or re-enter the view as out-of-bounds moves (#4610)
The fix now lives in `GestureHandler`: `onPointerLeave` and
`onPointerEnter` mark the event as a move and pass it to
`onPointerOutOfBounds`, so every handler applies these moves. The
Pan-specific overrides are removed. The description below explains the
original Pan symptoms, which this change still fixes.
## Description
On web, `PointerEventManager` dispatches the `pointermove` that takes a
tracked pointer out of the view as `onPointerLeave`, and the one that
brings it back as `onPointerEnter`. `PanGestureHandler` did not override
either, so for those moves it never updated the tracker, the last
coordinates or the velocity, and never checked whether to activate. As a
result:
- `onUpdate` does not fire for the move that leaves or re-enters the
view.
- If the pointer is released right after, `onEnd` reports the last
in-bounds position instead of the release position.
- A Pan in `BEGAN` whose activating move lands outside the view does not
activate on that move.
This PR makes `PanGestureHandler` handle the leave and enter moves like
any other move: it tracks the pointer, updates the coordinates and
velocity, checks activation and sends the update. With
`shouldCancelWhenOutside`, leaving the view still cancels the gesture as
before. The shared tracking code of `onPointerMove` and
`onPointerOutOfBounds` moves to a private `trackMove` helper.
Fixes #4607
## Test plan
Added tests to `src/web/handlers/__tests__/PanGestureHandler.test.ts`:
- The move that leaves the view sends an update with the new
translation, and `onEnd` reports the release position.
- The move that re-enters the view does the same.
- The move that leaves the view activates a Pan that is still in
`BEGAN`.
- With `shouldCancelWhenOutside`, leaving the view still cancels the
gesture.
Without the fix, the first three fail. With it, `yarn test` passes (23
suites, 227 tests), and `yarn ts-check`, ESLint and Prettier are clean.
---------
Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
Co-authored-by: Michał <michal.bert@swmansion.com>1 parent 0b36e9d commit 2202d7b
2 files changed
Lines changed: 115 additions & 2 deletions
File tree
- packages/react-native-gesture-handler/src/web/handlers
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
| 379 | + | |
| 380 | + | |
380 | 381 | | |
381 | 382 | | |
382 | | - | |
| 383 | + | |
| 384 | + | |
383 | 385 | | |
384 | 386 | | |
385 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
24 | 44 | | |
25 | 45 | | |
26 | 46 | | |
| |||
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
45 | 78 | | |
46 | 79 | | |
47 | 80 | | |
| |||
307 | 340 | | |
308 | 341 | | |
309 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
0 commit comments