Skip to content

Commit 545b190

Browse files
committed
test(gestures): a scroll-edge pan cancels its first moves while every scroller under it is at the edge
spec:AST-094 FR19 and DEC-18 (proposed in meta#8628): a scrollEdge pan may cancel its touch's moves from the first one, only while every scroller under the finger sits at its edge and the finger moves away from it, and only the moves the browser would rubber-band; it still begins at FR17's 10 px. The first case reads the first 2 px move cancelled at the edge and fails on this head; the others keep what must not change: room to scroll leaves every move to the browser, a first move toward the content too, a pan without scrollEdge cancels nothing before it begins, and a touch the browser took for a scroll stays the browser's when the list reaches its edge.
1 parent 1741e3d commit 545b190

1 file changed

Lines changed: 73 additions & 16 deletions

File tree

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

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -759,22 +759,79 @@ describe('GestureHost', () => {
759759
touch('touchend', card, [{...finger, y: 88}], [], 64);
760760
});
761761

762-
it('leaves a scroll-edge pan to claim at its begin', () => {
763-
const {sheet} = mount('<div id="sheet"></div>');
764-
const pan = new PanGestureRecognizer({
765-
name: 'sheet',
766-
direction: 'down',
767-
scrollEdge: true,
768-
});
769-
detachers.push(host.attach(sheet, pan));
770-
const finger = {id: 1, x: 50, y: 100};
771-
touch('touchstart', sheet, [finger], [finger], 0);
772-
const at = (y: number, time: number) =>
773-
touch('touchmove', sheet, [{...finger, y}], [{...finger, y}], time);
774-
expect(at(107, 16).defaultPrevented).toBe(false);
775-
expect(at(112, 32).defaultPrevented).toBe(true);
776-
expect(pan.state).toBe('began');
777-
touch('touchend', sheet, [{...finger, y: 112}], [], 48);
762+
describe("a scroll-edge pan's first moves (spec:AST-094 FR19, DEC-18)", () => {
763+
/** A sheet whose own list sits under the finger, scrolled to `scrollTop`. */
764+
function sheetOverList(scrollTop: number, options = {scrollEdge: true}) {
765+
const {list, row} = mount(
766+
'<div id="list" style="overflow-y: auto"><div id="row"></div></div>',
767+
);
768+
scrollable(list, {scrollTop, scrollHeight: 1000, clientHeight: 400});
769+
const pan = new PanGestureRecognizer({
770+
name: 'sheet',
771+
direction: 'down',
772+
...options,
773+
});
774+
detachers.push(host.attach(row, pan));
775+
const finger = {id: 1, x: 50, y: 100};
776+
touch('touchstart', row, [finger], [finger], 0);
777+
const at = (y: number, time: number, cancelable = true) =>
778+
touch(
779+
'touchmove',
780+
row,
781+
[{...finger, y}],
782+
[{...finger, y}],
783+
time,
784+
cancelable,
785+
);
786+
const lift = (y: number, time: number) =>
787+
touch('touchend', row, [{...finger, y}], [], time);
788+
return {list, pan, at, lift};
789+
}
790+
791+
it('cancels the moves from the first one while every scroller under the finger is at its edge and the finger pulls away from it; the pan still begins at 10 px', () => {
792+
const {pan, at, lift} = sheetOverList(0);
793+
expect(at(102, 16).defaultPrevented).toBe(true);
794+
expect(pan.state).toBe('possible');
795+
expect(at(107, 32).defaultPrevented).toBe(true);
796+
expect(pan.state).toBe('possible');
797+
expect(at(112, 48).defaultPrevented).toBe(true);
798+
expect(pan.state).toBe('began');
799+
lift(112, 64);
800+
});
801+
802+
it('leaves the moves to the browser while a scroller under the finger can still scroll that way', () => {
803+
const {pan, at, lift} = sheetOverList(50);
804+
expect(at(102, 16).defaultPrevented).toBe(false);
805+
expect(at(107, 32).defaultPrevented).toBe(false);
806+
expect(at(112, 48).defaultPrevented).toBe(false);
807+
expect(pan.state).toBe('failed');
808+
lift(112, 64);
809+
});
810+
811+
it('leaves a first move toward the content to the browser', () => {
812+
const {at, lift} = sheetOverList(0);
813+
expect(at(98, 16).defaultPrevented).toBe(false);
814+
lift(98, 32);
815+
});
816+
817+
it('cancels nothing before a pan without scrollEdge begins', () => {
818+
const {pan, at, lift} = sheetOverList(0, {scrollEdge: false});
819+
expect(at(102, 16).defaultPrevented).toBe(false);
820+
expect(at(107, 32).defaultPrevented).toBe(false);
821+
expect(at(112, 48).defaultPrevented).toBe(true);
822+
expect(pan.state).toBe('began');
823+
lift(112, 64);
824+
});
825+
826+
it('cancels nothing once the browser has taken the touch for a scroll', () => {
827+
const {list, at, lift} = sheetOverList(50);
828+
// The browser scrolls the list: its moves can no longer be cancelled.
829+
at(102, 16, false);
830+
// The list reaches its edge under the same finger: still the browser's.
831+
scrollable(list, {scrollTop: 0});
832+
expect(at(107, 32).defaultPrevented).toBe(false);
833+
lift(107, 48);
834+
});
778835
});
779836

780837
it('names the pointer a finger, a pen or a mouse is driven by', () => {

0 commit comments

Comments
 (0)