Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/bottom-sheet-fitting-content-slow-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] BottomSheet: in Safari, and in every browser on iPhone and iPad, a swipe on the sheet's content that starts slowly now moves the sheet, so a slow swipe down can close it. Before, on content that fits, when the finger's first move was 8 px or less, in either direction, the sheet stopped answering that swipe: it stayed open, or moved a few pixels and fell back. Fast swipes and swipes on the grab bar already worked, and Chromium browsers were not affected. The fix applies wherever the touched content has nothing to scroll: a sheet whose content fits, and the fixed header or footer around a list. That includes the PowerSearch and Tokenizer sheets. At the top of a list that scrolls, a pull down now also moves the sheet when the finger first wobbles up by less than 5 px; a move up of 5 px or more still scrolls the list. In every browser, the sheet now decides who owns a touch on its content once, at the first move past 8 px. A mostly vertical pull at a scroll edge is the sheet's. A mostly sideways move, such as a swipe along a row of chips, is not the sheet's for the rest of that touch. Before, at the top of a list, a sideways swipe that drifted more than 8 px down, or a pull that began more sideways than down, also moved the sheet.

@imdreamrunner
321 changes: 321 additions & 0 deletions packages/core/src/BottomSheet/useSheetGestures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,327 @@ describe('useSheetGestures', () => {
}
});

describe('content that fits', () => {
// Nothing scrolls, so a touch arms both edges at touch-down.
function fittingSheet() {
const {hook} = setup({
snapHeights: () => [200],
offscreenBlockEndInset: TOUCH_RESERVE,
});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 200,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
return {hook, el};
}

it.each([
{first: 1, isFirstCancelled: false},
{first: 4, isFirstCancelled: false},
{first: 5, isFirstCancelled: true},
{first: 8, isFirstCancelled: true},
])(
'promotes a pull-down whose first move is $first px, under the drag slop',
({first, isFirstCancelled}) => {
const {hook, el} = fittingSheet();
let start!: Event;
let pull!: Event;
act(() => {
touch(el, 'touchstart', 100);
start = touch(el, 'touchmove', 100 + first);
});
// A tap's wobble keeps its click. Past the wobble, the sheet cancels
// the pan.
expect(start.defaultPrevented).toBe(isFirstCancelled);
expect(hook.result.current.isDragging).toBe(false);
act(() => {
pull = touch(el, 'touchmove', 140);
});
expect(pull.defaultPrevented).toBe(true);
expect(hook.result.current.isDragging).toBe(true);
// The drag starts from the touch-down point, so the sheet loses no
// travel.
expect(liveOffset(hook)).toBe(40);
},
);

it('promotes a pull-down that creeps a pixel at a time through the slop', () => {
const {hook, el} = fittingSheet();
const moves: Event[] = [];
act(() => {
touch(el, 'touchstart', 100);
for (let y = 101; y <= 108; y += 1) {
moves.push(touch(el, 'touchmove', y));
}
});
expect(hook.result.current.isDragging).toBe(false);
expect(moves.map(move => move.defaultPrevented)).toEqual([
false,
false,
false,
false,
true,
true,
true,
true,
]);
act(() => {
touch(el, 'touchmove', 109);
});
expect(hook.result.current.isDragging).toBe(true);
expect(liveOffset(hook)).toBe(9);
});

it('promotes a pull-down after the finger drifts up as it lands', () => {
const {hook, el} = fittingSheet();
let drift!: Event;
let pull!: Event;
act(() => {
touch(el, 'touchstart', 100);
drift = touch(el, 'touchmove', 99);
});
expect(drift.defaultPrevented).toBe(false);
expect(hook.result.current.isDragging).toBe(false);
act(() => {
pull = touch(el, 'touchmove', 140);
});
expect(pull.defaultPrevented).toBe(true);
expect(hook.result.current.isDragging).toBe(true);
expect(liveOffset(hook)).toBe(40);
});

it('claims a pull-up after the finger drifts down as it lands', () => {
const {hook, el} = fittingSheet();
let pull!: Event;
act(() => {
touch(el, 'touchstart', 300);
touch(el, 'touchmove', 303);
pull = touch(el, 'touchmove', 250);
});
// The sheet takes the pull from the touch-down, and cancels its pan.
expect(pull.defaultPrevented).toBe(true);
expect(hook.result.current.isDragging).toBe(true);
expect(-liveOffset(hook)).toBeCloseTo(
rubberBand(50, SHEET_HEIGHT - TOUCH_RESERVE),
6,
);
});
});

it('gives a list at its top to its scroll on an upward first move, and takes no later pull-down', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
let back!: Event;
act(() => {
touch(el, 'touchstart', 100);
// A kept move of 5 px commits iOS Safari to the list's pan.
touch(el, 'touchmove', 95);
back = touch(el, 'touchmove', 150);
});
// The scroll owns this touch, so the drag does not change hands.
expect(back.defaultPrevented).toBe(false);
expect(hook.result.current.isDragging).toBe(false);
});

it('gives a list at its end to its scroll on a downward first move, and claims no later pull-up', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 600,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
// Settle at the lower detent, where the sheet claims a pull up at the
// end.
down(hook, 0, 0, el);
move(hook, 180, 700, el);
up(hook, 180, 1100, el);
expect(hook.result.current.settledOffset).toBe(200);
let back!: Event;
act(() => {
touch(el, 'touchstart', 300);
touch(el, 'touchmove', 305);
back = touch(el, 'touchmove', 250);
});
expect(back.defaultPrevented).toBe(false);
});

it('promotes a pull-down at the top of a list after the finger wobbles up less than a tap does', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
let wobble!: Event;
let pull!: Event;
act(() => {
touch(el, 'touchstart', 100);
// A kept move of 4 px commits no native pan, so it decides nothing.
wobble = touch(el, 'touchmove', 96);
pull = touch(el, 'touchmove', 106);
});
expect(wobble.defaultPrevented).toBe(false);
expect(pull.defaultPrevented).toBe(true);
expect(hook.result.current.isDragging).toBe(false);
act(() => {
touch(el, 'touchmove', 140);
});
expect(hook.result.current.isDragging).toBe(true);
expect(liveOffset(hook)).toBe(40);
});

it('claims a pull-up at the end of a list after the finger wobbles down less than a tap does', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 600,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
// Settle at the lower detent, where the sheet claims a pull up at the
// end.
down(hook, 0, 0, el);
move(hook, 180, 700, el);
up(hook, 180, 1100, el);
expect(hook.result.current.settledOffset).toBe(200);
let wobble!: Event;
let pull!: Event;
act(() => {
touch(el, 'touchstart', 300);
wobble = touch(el, 'touchmove', 304);
pull = touch(el, 'touchmove', 250);
});
expect(wobble.defaultPrevented).toBe(false);
// The sheet takes the pull from the touch-down, and cancels its pan.
expect(pull.defaultPrevented).toBe(true);
expect(hook.result.current.isDragging).toBe(true);
expect(liveOffset(hook)).toBe(150);
});

it.each([
{content: 'content that fits', scrollHeight: 200},
{content: 'a list at its top', scrollHeight: 800},
])(
'leaves a sideways swipe on $content to the row for the whole touch, also when it drifts down, turns into a pull, or comes back up',
({scrollHeight}) => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
const moves: Event[] = [];
act(() => {
touch(el, 'touchstart', 100, 1, 'direct', undefined, 0);
// A swipe along a row of chips whose finger drifts 40 px down.
moves.push(touch(el, 'touchmove', 103, 1, 'direct', undefined, 20));
moves.push(touch(el, 'touchmove', 109, 1, 'direct', undefined, 60));
moves.push(touch(el, 'touchmove', 140, 1, 'direct', undefined, 150));
// The finger then pulls down, farther than it went sideways.
moves.push(touch(el, 'touchmove', 300, 1, 'direct', undefined, 152));
// It then comes back up, past where it began.
moves.push(touch(el, 'touchmove', 60, 1, 'direct', undefined, 154));
});
expect(moves.map(move => move.defaultPrevented)).toEqual([
false,
false,
false,
false,
false,
]);
expect(hook.result.current.isDragging).toBe(false);
},
);

it('takes no pull whose first move past the slop is more sideways than down, also when the pull then turns down', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
let diagonal!: Event;
let down!: Event;
act(() => {
touch(el, 'touchstart', 100, 1, 'direct', undefined, 0);
diagonal = touch(el, 'touchmove', 120, 1, 'direct', undefined, 30);
down = touch(el, 'touchmove', 250, 1, 'direct', undefined, 34);
});
expect(diagonal.defaultPrevented).toBe(false);
expect(down.defaultPrevented).toBe(false);
// A drag that began here would move the sheet 150 px at once.
expect(hook.result.current.isDragging).toBe(false);
});

it('decides at the drag slop, so a pull on content that fits whose first move is diagonal starts the drag', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 200,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
let first!: Event;
act(() => {
touch(el, 'touchstart', 100, 1, 'direct', undefined, 0);
// 6 px sideways and 5 px down: under the slop, so nothing is decided.
first = touch(el, 'touchmove', 105, 1, 'direct', undefined, 6);
});
expect(first.defaultPrevented).toBe(false);
expect(hook.result.current.isDragging).toBe(false);
act(() => {
touch(el, 'touchmove', 112, 1, 'direct', undefined, 7);
});
expect(hook.result.current.isDragging).toBe(true);
// A sideways drift after the drag begins does not end it.
act(() => {
touch(el, 'touchmove', 140, 1, 'direct', undefined, 90);
});
expect(hook.result.current.isDragging).toBe(true);
expect(liveOffset(hook)).toBe(40);
});

it('gives the touch to the content when a list is off its top at the drag slop, and takes no later pull-down', () => {
const {hook} = setup({snapHeights: () => [200]});
const el = makeScroller({
scrollTop: 0,
clientHeight: 200,
scrollHeight: 800,
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
let back!: Event;
act(() => {
touch(el, 'touchstart', 100);
// The list scrolls under the finger before the pull passes the slop.
el.scrollTop = 12;
touch(el, 'touchmove', 110);
el.scrollTop = 0;
back = touch(el, 'touchmove', 150);
});
expect(back.defaultPrevented).toBe(false);
expect(hook.result.current.isDragging).toBe(false);
});

it("keeps a stylus pulling up on the body at the tallest detent on a pen's stretch, capped at 48 px", () => {
const {hook} = setup({
snapHeights: () => [200],
Expand Down
Loading
Loading