Skip to content

Commit fafaf5e

Browse files
committed
feat(gestures): a scroll-edge pan holds its finger from the first move away from an edge
spec:AST-094 FR19 and DEC-18 (proposed in meta#8628). GestureRecognizer gains keepsTouch(touchId), false by default and reached by the host through recognizerInternals: whether it holds that finger before it begins. A scrollEdge pan does while it is possible, the touch is a finger the browser has not taken, its travel so far goes the pan's own way, and no scroller under the finger can scroll for it (the probe its begin already reads), so only moves the browser would rubber-band are held, never a real scroll. The host's blocking touchmove check cancels a move a participant holds, as it does a claimed one; the arena already holds that move when the check runs, since the host feeds it from its window-capture subscriber first. The pan still begins at 10 px; a mouse or a pen is never held. The README says so.
1 parent 8e400ea commit fafaf5e

6 files changed

Lines changed: 54 additions & 5 deletions

File tree

‎.changeset/gesture-host-owner.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'@astryxdesign/core': patch
33
---
44

5-
[chore] Internal: the gesture host becomes the one document-level touch owner: a scroll lock's page hold, finger scrolls, the finger count, touch gates, and a kept press for continuous-tracking controls, whose element gets `touch-action: manipulation` where the pointer is coarse. A second finger fails a one-finger pan that has not claimed, so the page can pinch. Where the primary pointer is fine, the host attaches nothing and registers no listener, following the pointer when it changes; a recognizer that reads each event's pointer itself opts out with `perEventPointer`, and a press tracker with it paints a finger's press feedback only, with no control event and no mouse or pen press. A press tracker whose hold acts (a stepper's hold-repeat) can bring a selection lock for its presses, as a recognizer can. Internal, for the touch components that adopt them; not exported from the package entry point.
5+
[chore] Internal: the gesture host becomes the one document-level touch owner: a scroll lock's page hold, finger scrolls, the finger count, touch gates, and a kept press for continuous-tracking controls, whose element gets `touch-action: manipulation` where the pointer is coarse. A second finger fails a one-finger pan that has not claimed, so the page can pinch. A scroll-edge pan holds its finger from the first move that pulls away from an edge every scroller under it is at, so those moves are cancelled before it begins. Where the primary pointer is fine, the host attaches nothing and registers no listener, following the pointer when it changes; a recognizer that reads each event's pointer itself opts out with `perEventPointer`, and a press tracker with it paints a finger's press feedback only, with no control event and no mouse or pen press. A press tracker whose hold acts (a stepper's hold-repeat) can bring a selection lock for its presses, as a recognizer can. Internal, for the touch components that adopt them; not exported from the package entry point.
66

77
@vjeux

‎packages/core/src/gestures/GestureHost.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,9 @@ export class GestureHost {
16891689
/**
16901690
* Cancel a `touchmove` while a recognizer owns one of its fingers. A touch
16911691
* no recognizer owns keeps its moves (`spec:AST-094` FR19): nothing is
1692-
* cancelled before a recognizer begins, or for a touch it does not track.
1692+
* cancelled before a recognizer begins, or for a touch it does not track,
1693+
* unless a recognizer holds that finger already (a scroll-edge pan pulling
1694+
* away from an edge every scroller under it is at; FR19, DEC-18).
16931695
*/
16941696
private cancelIfClaimed(event: TouchEvent): void {
16951697
if (!event.cancelable || event.defaultPrevented) {
@@ -1704,7 +1706,12 @@ export class GestureHost {
17041706
id != null &&
17051707
(this.arena.isClaimed(id) ||
17061708
(this.isCoarse &&
1707-
this.arena.consumerOf(id)?.keepsTouch?.(id) === true))
1709+
this.arena.consumerOf(id)?.keepsTouch?.(id) === true) ||
1710+
// A recognizer that holds the finger before it begins: a
1711+
// scroll-edge pan pulling away from an edge (FR19, DEC-18).
1712+
this.arena
1713+
.participantsOf(id)
1714+
.some(recognizer => internals(recognizer).keepsTouch(id)))
17081715
) {
17091716
event.preventDefault();
17101717
return;

‎packages/core/src/gestures/GestureRecognizer.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ export abstract class GestureRecognizer {
351351
return this.options.shouldBegin?.(this) ?? true;
352352
}
353353

354+
/**
355+
* @internal Whether this recognizer holds `touchId` before it begins: the
356+
* host then cancels that finger's moves as for a touch a recognizer owns.
357+
* None does by default (`spec:AST-094` FR19); a scroll-edge pan holds a
358+
* finger pulling away from an edge every scroller under it is at.
359+
*/
360+
protected keepsTouch(_touchId: number): boolean {
361+
return false;
362+
}
363+
354364
/** UIKit's `canPrevent(_:)`: whether recognizing fails `other`. */
355365
canPrevent(_other: GestureRecognizer): boolean {
356366
return true;

‎packages/core/src/gestures/PanGestureRecognizer.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,32 @@ export class PanGestureRecognizer extends GestureRecognizer {
364364
this.offset = {x: -swallowed.x, y: -swallowed.y};
365365
}
366366

367+
/**
368+
* A scroll-edge pan holds its finger from the first move while every
369+
* scroller under it is at its edge and the finger pulls away from that
370+
* edge, the pan's own way (`spec:AST-094` FR19, DEC-18):
371+
* the browser would only rubber-band there. It still begins at its
372+
* hysteresis; a move the content can still scroll stays the browser's.
373+
*/
374+
protected override keepsTouch(touchId: number): boolean {
375+
const touch = this.touches.get(touchId);
376+
if (
377+
!this.scrollEdge ||
378+
this.state !== 'possible' ||
379+
touch == null ||
380+
touch.pointerType !== 'touch' ||
381+
touch.takenByBrowser
382+
) {
383+
return false;
384+
}
385+
const moved = this.raw;
386+
return (
387+
(moved.x !== 0 || moved.y !== 0) &&
388+
this.classify(moved) === 'begin' &&
389+
!this.nativeCanScroll(moved.x, moved.y)
390+
);
391+
}
392+
367393
private nativeCanScroll(dx: number, dy: number): boolean {
368394
for (const touch of this.touches.values()) {
369395
if (touch.scroll?.canScroll(dx, dy) === true) {

‎packages/core/src/gestures/README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ presses nothing.
318318
- **Claim at the begin.** A pan claims its touch only as it begins, at
319319
UIKit's 10 pt (`spec:AST-094` FR19), before WebKit commits a slow drag to
320320
a scroll at 10–11 px; a drag the browser took first stays the browser's
321-
(FR14).
321+
(FR14). One exception: a `scrollEdge` pan cancels its finger's moves from
322+
the first one while every scroller under the finger is at its edge and
323+
the finger pulls away from it, the pan's own way (the browser could only
324+
rubber-band there); it still begins at 10 pt.
322325
Measured in Mobile Safari (iOS 26.2): `touchmove` arrives from the first
323326
pixel; on a scrollable element WebKit commits to scrolling at 10 to 11 px
324327
(the last cancelable `touchmove` at 10 px), and cancelling every
@@ -355,7 +358,9 @@ presses nothing.
355358
finger. This is the sheet over its own list: the pan begins only if nothing
356359
under the touch could scroll for that movement, the finger landed at the
357360
edge and pulls away from it. The browser has not committed yet, so beginning
358-
claims the touch and the content never moves.
361+
claims the touch and the content never moves. From the first move that
362+
pulls away from such an edge the pan already holds the finger, so its moves
363+
are cancelled before it begins and the page does not rubber-band either.
359364

360365
Who gets a drag is decided once, when it begins, as in UIKit: a drag that
361366
began as a scroll stays the scroll view's for its whole length (it scrolls

‎packages/core/src/gestures/recognizerInternals.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface RecognizerInternals {
3030
requiresFailureOf(other: GestureRecognizer): boolean;
3131
allowsSimultaneous(other: GestureRecognizer): boolean;
3232
shouldBegin(): boolean;
33+
keepsTouch(touchId: number): boolean;
3334
wantsTouch(touch: GestureTouch): boolean;
3435
deliverBegan(
3536
touches: ReadonlyArray<GestureTouch>,

0 commit comments

Comments
 (0)