Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): a BottomSheet touch release takes UIKit's sheet values, and turning back cancels (#10234)

Christopher Chedeau6309b0b380ba
diff --git a/.changeset/bottom-sheet-flick-closes.md b/.changeset/bottom-sheet-flick-closes.md
new file mode 100644
index 0000000000..609a3952e9
--- /dev/null
+++ b/.changeset/bottom-sheet-flick-closes.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] BottomSheet: a touch release takes the iOS sheet's measured values, and a release moving back toward where the drag began cancels. A release faster than about 1,000 px/s is a flick: it goes at least to the next detent in its direction, so a short fast flick at the lowest detent closes the sheet instead of springing back. From a higher detent, a flick that would carry past the next detent goes on, so a hard flick closes the sheet and a softer one stops at the next detent. A slow or medium touch throw now travels less than before, and a slow touch drag closes the sheet only past halfway to closed. A mouse or pen drag is unchanged.
+
+@vjeux
diff --git a/docs/specs/AST-094-touch-presentations/spec.md b/docs/specs/AST-094-touch-presentations/spec.md
index d563aea2bf..f47a320fda 100644
--- a/docs/specs/AST-094-touch-presentations/spec.md
+++ b/docs/specs/AST-094-touch-presentations/spec.md
@@ -668,7 +668,12 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
springs back. The decision MUST NOT change while the surface settles. The
same rule backs dismissing a BottomSheet, a Toast or a Lightbox, popping a
NavigationStack, and dismissing the keyboard; each use's commit point and
- projection are measured values (FR1, FR2). A row swipe keeps
+ projection are measured values (FR1, FR2). A BottomSheet's touch release takes
+ UIKit's measured sheet values. Its projection is 0.1 s of the release
+ velocity, and its commit point is halfway from its lowest detent to closed. A
+ release past its measured flick speed lands on the first position at or past
+ its projection, at least its next one. So a short fast flick at its lowest
+ detent closes it (`component:BottomSheet` FR19). A row swipe keeps
`spec:AST-057`'s own release rule.
- **FR37 — Moving back cancels.** A release whose velocity points back
toward the start MUST cancel, whatever the travel so far.
diff --git a/docs/specs/components/BottomSheet/BottomSheet.spec.md b/docs/specs/components/BottomSheet/BottomSheet.spec.md
index e96edd1adb..ce10864dc8 100644
--- a/docs/specs/components/BottomSheet/BottomSheet.spec.md
+++ b/docs/specs/components/BottomSheet/BottomSheet.spec.md
@@ -70,6 +70,10 @@ gap note.
- Released default preserved: `yes`; with no `padding` prop and no theme
padding, the Content area insets by `--spacing-4` on every logical edge, and
`padding={0}` keeps an unpadded Content area
+- Touch release (FR19): a touch release follows UIKit's sheet. A slow or
+ medium touch throw travels less than it did, and a slow touch drag closes
+ the sheet only past halfway from the lowest detent to closed, where it
+ closed past 40 %. A mouse or pen drag is unchanged.
- Compatibility class: no public prop, type, default, or export changes.
Stacking, the replace handoff, and non-modal top-layer hosting are behavior
of the existing component, tagged `[feat]` (`spec:AST-017/FR7`: a compatible
@@ -169,7 +173,7 @@ remain documented in `BottomSheet.doc.mjs`.
| FR16 | An open modal sheet is a focus region through Core's shared focus-region module (`component:Dialog/DEC-2`): in the top sheet, Tab from the last tabbable control moves focus to the first and Shift+Tab from the first moves focus to the last, so focus never leaves the sheet for the browser's own interface. A covered or closing sheet does not answer Tab, and a non-modal sheet contains nothing (FR11). A switcher step (the deprecated BottomSheetSwitcher) is the exception to DEC-2, as `component:Dialog` DEC-2 states. | `component:Dialog/DEC-2` |
| FR17 | A BottomSheet open on the server, by its own `isOpen` or as a `BottomSheetSwitcher`'s active sheet, renders closed until hydration (no open styles, no `aria-modal`, the markup of a closed sheet) and opens in the render after hydration, the first that can enter its native host; it never claims a modality it does not have (`spec:AST-020` FR1, WCAG 2.2 SC 4.1.2). The server and hydrating renders produce the same markup (`spec:AST-013` FR9), and the open after hydration is settled, with no entry motion; later opens and closes animate as usual (`spec:AST-013` FR13). | `spec:AST-020` FR1 |
| FR18 | A finger's pull up past the tallest detent stretches the sheet on `spec:AST-094` FR3's rubber band, the same on every pull, with no hold. The sheet's surface reaches below the screen far enough for the whole stretch and the release, so the page under it never shows. A pull on the sheet's body stretches it as a pull on the grabber does, once the content has no room left to scroll that way: content that fits stretches at once, and a long list scrolls to its end first, then holds still while the sheet stretches. At every detent, a list that reaches its end mid-pull holds still while the sheet takes the rest of the pull. A sheet the caller sizes or styles keeps 48 px below the screen, and its stretch stops there. An inline block size, any `xstyle` and any class name count, because the sheet cannot read their rules. A mouse or a pen keeps its own resisted stretch, at most 48 px (`spec:AST-017` FR59). | DEC-3; `spec:AST-094` FR3 |
-| FR19 | A release settles on the detent nearest its projected position (`spec:AST-094` FR36); a release whose velocity points back toward its start returns to its starting detent (`spec:AST-094` FR37). An `info` sheet whose projection passes the dismiss point closes; a `form` or `required` sheet settles on its shortest detent (FR7). A sheet that a touch release closes leaves on its close spring from the release speed (`spec:AST-094` FR38), UIKit's measured swipe dismissal `springs.sheetDismissSwipe`, a motion role that the theme's `tempo` scales (`spec:AST-094` FR4, FR45). Its scrim fades for as long as that spring takes to settle at the theme's `tempo`, so the two finish together (`spec:AST-094` FR45's spring tiers; `spec:AST-108` FR4a). Under reduced motion its exit follows FR15. Implementation gap: the settle on a detent plays `--ease-standard` over the theme's `--duration-medium`, at a speed set by the distance left rather than the finger's (`spec:AST-094` FR38). Implementation gap: in WebKit, the settle stops advancing while the main thread is blocked (`spec:AST-094` FR5). Implementation gap: a release whose velocity points back toward its start still commits when it follows a net downward drag and its projection passes the dismiss point, or when its projection lies nearer the next detent in the drag's direction (`spec:AST-094` FR37). Implementation gap: a release after 48 px of travel or less projects nothing: it is judged where the finger lifted, so a short fast flick closes an `info` sheet only when the finger itself lifts past the dismiss point (`spec:AST-094` FR36). Implementation gap: a mouse or pen close plays the stylesheet's exit, not the close spring (`spec:AST-094` FR43, FR45). | `spec:AST-094` FR4, FR5, FR36, FR37, FR38, FR43, FR45; `spec:AST-108` FR4a; FR7 |
+| FR19 | A release settles on the detent nearest its projected position (`spec:AST-094` FR36); a release whose velocity points back toward its start returns to its starting detent (`spec:AST-094` FR37). An `info` sheet whose projection passes the dismiss point closes; a `form` or `required` sheet settles on its shortest detent (FR7). Under a finger, the projection is 0.1 s of the release velocity (`sheet.release.projectionSeconds`, measured from UIKit's sheet), closed counts as one position, and the dismiss point is halfway from the lowest detent to closed. A touch release slower than 250 px/s (`sheet.release.minProjectionSpeed`, measured) projects nothing, so it settles on the position nearest where it was let go. From 1,008 px/s (`sheet.release.fastSpeed`, as UIKit's sheet counts a flick), a touch release is a flick: it lands on the first position at or past its projection, at least the next one in its direction. So a flick goes on past the next position once it is faster than 10 px/s for each pixel left to that position, and a flick at the lowest detent closes the sheet. A sheet that a touch release closes leaves on its close spring from the release speed (`spec:AST-094` FR38), UIKit's measured swipe dismissal `springs.sheetDismissSwipe`, a motion role that the theme's `tempo` scales (`spec:AST-094` FR4, FR45). Its scrim fades for as long as that spring takes to settle at the theme's `tempo`, so the two finish together (`spec:AST-094` FR45's spring tiers; `spec:AST-108` FR4a). Under reduced motion its exit follows FR15. Implementation gap: the settle on a detent plays `--ease-standard` over the theme's `--duration-medium`, at a speed set by the distance left rather than the finger's (`spec:AST-094` FR38). Implementation gap: in WebKit, the settle stops advancing while the main thread is blocked (`spec:AST-094` FR5). Implementation gap: under a mouse or pen, a release whose velocity points back toward its start still commits when it follows a net downward drag and its projection passes the dismiss point, or when its projection lies nearer the next detent in the drag's direction (`spec:AST-094` FR37). Implementation gap: under a mouse or pen, the projection is a scroll view's, a release after 48 px of travel or less projects nothing, and the dismiss point is a dismiss line, so a short fast flick closes an `info` sheet only when the pointer itself lifts past it (`spec:AST-094` FR36, FR43). Implementation gap: a mouse or pen close plays the stylesheet's exit, not the close spring (`spec:AST-094` FR43, FR45). | `spec:AST-094` FR4, FR5, FR36, FR37, FR38, FR43, FR45; `spec:AST-108` FR4a; FR7; DEC-4 |
| FR20 | A standalone sheet (not a switcher step) removed while open is closed for focus: when it was the standalone or top sheet and focus was inside it, or fell to the body with its removal, focus returns as FR9 (modal) or FR11 (non-modal) state, to `finalFocusRef`, else the opener while it is still connected; with a sheet open beneath, focus goes into that revealed sheet by FR9. An FR10 replace keeps its handoff to the entering sheet, and a switcher step's change keeps FR12's handoff. Removing a whole stack in one update returns focus once, as FR9 closes it: to the bottom sheet's `finalFocusRef` or opener. Removing a covered sheet under a top sheet that stays moves no focus, because focus is in the top sheet. A removed opener moves no focus and raises no error. Implementation gap: a `BottomSheetSwitcher` flow removed while open, alone or as the bottom level of a stack, returns no focus. | `spec:AST-020/FR1` (WCAG 2.2 SC 2.4.3); FR9; FR11 |
### Allowed variation
@@ -396,7 +400,7 @@ a decision that they must remain unthemeable.
| FR16 | `BottomSheet.test.tsx` focus-region suite | Modal and non-modal sheets; Tab and Shift+Tab at the sheet's edge | Tab from the last control leaves a modal sheet, or a non-modal sheet captures Tab | `audit:BottomSheet/accessibility` |
| FR17 | `BottomSheet.ssr.test.tsx`; `BottomSheetSwitcher.test.tsx` flow that mounts open | Open on the server; hydration; a closed sheet's markup | An open server render with `aria-modal`, open styles, or markup unlike a closed one, a hydration error, no `showModal()` after hydration, an entry motion on the open right after hydration, or none on a later open fails. | `audit:BottomSheet/accessibility` |
| FR18 | `useSheetGestures.test.ts` stretch suites; `BottomSheetPanel.test.tsx` reserve cases; `BottomSheetDrag.a11y.chromium.spec.ts` | Three finger pulls past the top; short content pulled up on its body at five points, the first pull and every one after it; a long list pulled past its end; a mouse pull and a pen pull | A capped or held stretch, a pull that stretches less than the one before it, a body pull on short content that moves nothing, a long list that never stretches the sheet once at its end or rubber-bands itself while the sheet stretches, or a reserve under 40% of the viewport on a device with a touch pointer fails, unless the caller sizes or styles the sheet (48 px). | `audit:BottomSheet/behavior` |
-| FR19 | `BottomSheetDetent.interaction.browser.spec.ts`; `BottomSheetRelease.a11y.chromium.spec.ts`; `useSheetGestures.test.ts`; `BottomSheetDragExit.test.tsx`; `snapOffsets.test.ts` | On the Snap points story under real touch input: a slow release between detents, a 2,000 px/s downward flick, the settle to a detent with its curve recorded (FR19's FR38 gap), in Chromium the settle through a 700 ms main-thread block (`spec:AST-094` FR5; WebKit's gap is skipped), and a rendering trace of the settle in Chromium. Touch: a drag's close, a reopen during it, its scrim at tempo 0.75, 1 and 1.5. Mouse: a close; one under reduced motion. A close from a control | A slow release that lands off the nearest detent, a flick past the dismiss point that leaves the sheet open, a touch exit that starts from rest, a scrim that fades longer or shorter than the close spring settles, a mouse drag that plays the close spring, a reduced-motion mouse close that moves, a settle that ends off the detent, or a settle that stalls while the main thread is blocked, or lays out or paints during the settle, fails | `audit:BottomSheet/behavior` |
+| FR19 | `BottomSheetDetent.interaction.browser.spec.ts`; `BottomSheetRelease.a11y.chromium.spec.ts`; `useSheetGestures.test.ts` release suite; `resolveSnapPoint.test.ts`; `BottomSheetDragExit.test.tsx`; `snapOffsets.test.ts` | Snap points, real touch: a slow release between detents; 2,000 and 1,200 px/s flicks from tall; the settle, its curve recorded (FR38 gap); in Chromium, the settle through a 700 ms main-thread block (`spec:AST-094` FR5) and its rendering trace. Touch: top-detent flicks short of and past the next detent; a flick at the lowest; a slower and a faster release on three stops; a slow drag each side of halfway to closed; a gentle throw; a short slow release; a drag's close, a reopen during it, its scrim at tempo 0.75, 1 and 1.5. Mouse: a quick short drag; a close; one under reduced motion. A close from a control | A release that lands off its position (a slow release: the nearest; a touch flick: the first at or past its projection), a flick past the dismiss point that leaves the sheet open, a faster touch release that stops short of a slower one, a touch exit that starts from rest, a scrim that fades longer or shorter than the close spring settles, a mouse drag that flicks or plays the close spring, a reduced-motion mouse close that moves, or a settle that ends off the detent, stalls while the main thread is blocked, or lays out or paints during the settle, fails | `audit:BottomSheet/behavior` |
| FR20 | `BottomSheetCloseFocus.test.tsx` "BottomSheet removed while open" suite; real-browser focus check in Chromium | A modal and a non-modal sheet removed from inside; `finalFocusRef`; the top sheet of a stack removed; a covered sheet removed under a top sheet that stays; a whole stack removed in one update; a sheet removed in the update that opens another; an opener removed with the sheet | Focus on `body` after a removal from inside, focus on `body` after a whole stack is removed, focus moved out of the top sheet when a covered sheet is removed, focus pulled out of a sheet that opened in the same update, or an error when the opener is gone, fails. | `audit:BottomSheet/behavior` |
Existing tests directly assert the Sheet panel target, Content area placement,
@@ -480,6 +484,45 @@ through a pull.
Rejected: a second mechanism for upward pulls, because the existing pull path
already carries them; it only gave too many of them to the content.
+### DEC-4 — A touch release takes UIKit's sheet values
+
+**Reference:** `component:BottomSheet/DEC-4`
+**Decider:** the component owner, 2026-11-02 and 2026-11-03; the spec owners,
+2026-11-05
+
+A touch release faster than about 1,000 px/s is a flick, and a flick goes at
+least to the next position in its direction, as UIKit's sheet measures it:
+1,008 px/s, with no more travel than a drag's first 8 px. So a short fast
+flick at the lowest detent closes the sheet, where the projection alone
+springs it back (FR19). A sheet a touch drag closes keeps the drag's speed: it
+leaves on its close spring, starting at the release speed.
+
+On a sheet with snap points, closing it with a flick takes a harder flick than
+moving it to the next snap point. A flick lands on the first position at or
+past its projection, 0.1 s of its velocity. So a flick above the lowest detent
+closes the sheet once its projection passes the lowest detent, and a softer
+one stops at the next detent. UIKit fits 164 measured releases with any
+projection from 0.092 to 0.104 s. On an iPhone 17 Pro, with medium 342 pt and
+gone 812 pt below large, a flick released at large closes from about 3,420
+pt/s.
+
+On 2026-11-03 the owner also limited the flick and the close spring to touch,
+because a short mouse drag that closes a sheet changes how it works on a
+desktop; a mouse or pen keeps its release. The spec owners then chose UIKit's
+measured model for every touch release, not for flicks alone, so a faster
+release never travels less than a slower one. A touch release moving back
+toward where the drag began still cancels, as `spec:AST-094` FR37 requires,
+where UIKit's sheet settles it by its landing.
+
+Rejected: projecting the release only, because a short fast flick then
+springs back although the hand meant to close the sheet. Rejected: a fixed
+multiple of the flick speed for a close from above the lowest detent, because
+the projection decides it. Rejected: closing from above the lowest detent only
+when the projection lands nearer closed than any detent, because a flick past
+the next detent goes on. Rejected: UIKit's projection for flicks
+alone, because a release just under the flick speed then travels further than
+one just over it.
+
## Open questions
- **OQ1 — Should Content area, Handle, or Scrim gain a stable public theming
diff --git a/packages/core/src/BottomSheet/BottomSheet.test.tsx b/packages/core/src/BottomSheet/BottomSheet.test.tsx
index a56e3c53ac..3c7377c4b1 100644
--- a/packages/core/src/BottomSheet/BottomSheet.test.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.test.tsx
@@ -242,6 +242,25 @@ function mockResizeObserverInstances(): ResizeObserverRecord[] {
return observers;
}
+/**
+ * Lays a sheet out `height` px tall, as the browser's resize observer would.
+ * A touch release lands by the sheet's geometry, so a touch dismissal needs
+ * one.
+ */
+function layOutSheet(
+ observers: ResizeObserverRecord[],
+ sheet: HTMLElement,
+ height = 400,
+) {
+ const observer = observers.find(instance => instance.observed.has(sheet));
+ act(() => {
+ observer?.callback(
+ [resizeEntry(height)],
+ observer as unknown as ResizeObserver,
+ );
+ });
+}
+
function finishSheetExit() {
fireEvent.transitionEnd(getSheet(), {propertyName: 'transform'});
}
@@ -1112,6 +1131,7 @@ describe('BottomSheet', () => {
it("a sheet opened from inside another sheet's content drags to dismiss by its own handle, and the covered host neither drags nor takes the pointer (FR6, FR7)", () => {
const onInnerOpenChange = vi.fn();
const onOuterOpenChange = vi.fn();
+ const observers = mockResizeObserverInstances();
render(
<BottomSheet isOpen onOpenChange={onOuterOpenChange} label="Outer">
Outer content
@@ -1135,6 +1155,10 @@ describe('BottomSheet', () => {
const innerHandle = innerDialog.querySelector<HTMLElement>(
'.astryx-bottom-sheet > [aria-hidden="true"]',
)!;
+ layOutSheet(
+ observers,
+ innerDialog.querySelector<HTMLElement>('.astryx-bottom-sheet')!,
+ );
// `setPointerCapture` is a prototype stub here, so record who captures.
const captured: Element[] = [];
const capture = vi
@@ -4308,8 +4332,10 @@ describe('BottomSheet', () => {
it("a touch swipe dismissal under reduced motion fades out in place on a fine pointer (design:reduced-motion DR2, a touch drag's release)", () => {
stubReducedMotion(false);
+ const observers = mockResizeObserverInstances();
render(<Controlled />);
const dialog = screen.getByRole('dialog');
+ layOutSheet(observers, getSheet());
drag(getHandle(), [{y: 0}, {y: 40}, {y: 120}], 'touch');
// Exiting: a transform end does not close the dialog, the fade does.
fireEvent.transitionEnd(getSheet(), {propertyName: 'transform'});
@@ -4338,8 +4364,10 @@ describe('BottomSheet', () => {
</>
);
}
+ const observers = mockResizeObserverInstances();
render(<Reopenable />);
const dialog = screen.getByRole('dialog');
+ layOutSheet(observers, getSheet());
drag(getHandle(), [{y: 0}, {y: 40}, {y: 120}], 'touch');
fireEvent.transitionEnd(getSheet(), {propertyName: 'opacity'});
expect(dialog).not.toHaveAttribute('open');
diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts
index 8c6f70f21d..a6f17f030f 100644
--- a/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts
+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetDetent.interaction.browser.spec.ts
@@ -188,6 +188,24 @@ test('a downward flick dismisses the sheet', async ({page}) => {
await expect(page.getByRole('dialog', {name: 'Nearby places'})).toBeHidden();
});
+test('a softer downward flick from the tall detent lands on the half detent', async ({
+ page,
+}) => {
+ const {driver, sheet, handle, halfTop} = await openSheet(page);
+ // 1,200 px/s: a flick, whose projection stops short of the half detent, so
+ // it goes one stop.
+ const script = flick(handle, {
+ velocity: {x: 0, y: 1200},
+ durationMs: 80,
+ hz: 120,
+ });
+ expect(releaseVelocity(script).y).toBeCloseTo(1200, -1);
+ await driver.play(script);
+ await waitForRest(sheet);
+ await expect(page.getByRole('dialog', {name: 'Nearby places'})).toBeVisible();
+ expect(await sheetTop(sheet)).toBeCloseTo(halfTop, 0);
+});
+
test('the settle lands on the detent, its curve recorded frame by frame', async ({
page,
}, testInfo) => {
diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetRelease.a11y.chromium.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetRelease.a11y.chromium.spec.ts
index 1e61a8a203..297ef1535f 100644
--- a/packages/core/src/BottomSheet/__tests__/BottomSheetRelease.a11y.chromium.spec.ts
+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetRelease.a11y.chromium.spec.ts
@@ -5,12 +5,17 @@
* @file BottomSheetRelease.a11y.chromium.spec.ts
* @input Built BottomSheet stories and real Chromium touch input (CDP), each
* event with its own timestamp
- * @output Browser evidence for a touch drag's close: the close and its
- * scrim's running fade play on one clock and end together. That holds at
- * each tempo, from the top snap point, and in a switcher flow. A mouse
- * close under reduced motion moves no further.
- * @position Chromium proof for the drag's close and its scrim. The page reads
- * the events' timestamps, so load cannot change the release speed.
+ * @output Browser evidence for the touch release: a fast short flick closes
+ * a sheet at its lowest detent, and its exit starts at the flick's speed.
+ * From the top snap point, a flick whose projection stops short of the
+ * next one stops there. One whose projection passes it closes the sheet.
+ * A faster release never stops short of a slower one. A short slow
+ * release keeps the sheet open. A quick short mouse drag keeps it open, and
+ * a mouse close under reduced motion moves no further. A drag's close and
+ * its scrim's running fade play on one clock and end together, at each
+ * tempo and in a switcher flow.
+ * @position Chromium proof for useSheetGestures' release. The page reads the
+ * events' timestamps, so load cannot change the release speed.
*/
import {
@@ -26,6 +31,7 @@ import {
type StaticServer,
} from '@astryxdesign/a11y-spec/storybook';
import {END_HOLD_MS} from '../../motion/animator';
+import {sheet as sheetTable} from '../../motion/uikit/sheet';
let storybook: StaticServer;
test.beforeAll(async () => {
@@ -113,6 +119,179 @@ async function drag(
});
}
+test('a fast short flick closes the sheet, which leaves at the speed of the flick', async ({
+ page,
+}) => {
+ const {dialog, sheet} = await openFilters(page);
+ const rest = await sheet.evaluate(el => el.getBoundingClientRect());
+ // Every frame's sheet top, until the dialog closes.
+ await page.evaluate(() => {
+ const frames = {tops: [] as number[], done: false};
+ (window as unknown as {sheetFrames: typeof frames}).sheetFrames = frames;
+ const record = () => {
+ const panel = document.querySelector('.astryx-bottom-sheet');
+ if (panel == null || document.querySelector('dialog[open]') == null) {
+ frames.done = true;
+ return;
+ }
+ frames.tops.push(panel.getBoundingClientRect().top);
+ requestAnimationFrame(record);
+ };
+ requestAnimationFrame(record);
+ });
+ const cdp = await page.context().newCDPSession(page);
+ // 30 px in 15 ms is 2,000 px/s: a flick, and too short to project.
+ await drag(cdp, sheet, 30, 15);
+ // The exit the page plays: the close spring on the sheet's `translate`.
+ // Its first keyframe step gives the speed it starts at. A closing dialog
+ // leaves the accessibility tree, so read the panel from the document.
+ const startSpeed = await page.evaluate(async () => {
+ const panel = document.querySelector<HTMLElement>('.astryx-bottom-sheet');
+ const offsetY = (frame: Keyframe) =>
+ Number.parseFloat(String(frame.translate ?? '0px').split(' ')[1] ?? '0');
+ for (let attempt = 0; attempt < 30; attempt += 1) {
+ for (const animation of panel?.getAnimations() ?? []) {
+ const effect = animation.effect;
+ if (!(effect instanceof KeyframeEffect)) {
+ continue;
+ }
+ const [first, second] = effect.getKeyframes();
+ if (first?.translate == null || second == null) {
+ continue;
+ }
+ const duration = Number(effect.getComputedTiming().duration);
+ const step =
+ ((second.computedOffset ?? 0) - (first.computedOffset ?? 0)) *
+ duration;
+ return ((offsetY(second) - offsetY(first)) / step) * 1000;
+ }
+ await new Promise(resolve => requestAnimationFrame(resolve));
+ }
+ return null;
+ });
+ expect(startSpeed).not.toBeNull();
+ expect(startSpeed ?? 0).toBeGreaterThan(sheetTable.release.fastSpeed);
+ await expect(dialog).toBeHidden({timeout: 2_000});
+ // A closing dialog leaves the accessibility tree at once, so wait for the
+ // dialog itself to close.
+ const read = async () =>
+ page.evaluate(
+ () =>
+ (window as unknown as {sheetFrames: {tops: number[]; done: boolean}})
+ .sheetFrames,
+ );
+ await expect
+ .poll(async () => (await read()).done, {timeout: 2_000})
+ .toBe(true);
+ // The sheet slides off from where the finger left it, and never turns back
+ // toward rest while any of it shows. The spring settles below the screen.
+ const {tops} = await read();
+ const shown = tops.filter(top => top < 844);
+ expect(shown.length, 'frames drawn before the dialog closed').toBeGreaterThan(
+ 0,
+ );
+ const turnsBack = shown.some((top, i) => i > 0 && top < shown[i - 1] - 0.5);
+ expect(turnsBack, tops.join(' ')).toBe(false);
+ expect(Math.max(...tops) - rest.top).toBeGreaterThan(100);
+});
+
+test('a short release under the flick speed keeps the sheet open', async ({
+ page,
+}) => {
+ const {dialog, sheet} = await openFilters(page);
+ const cdp = await page.context().newCDPSession(page);
+ // 30 px in 150 ms is 200 px/s.
+ await drag(cdp, sheet, 30, 150);
+ await expect
+ .poll(async () => sheet.evaluate(el => getComputedStyle(el).transform), {
+ timeout: 2_000,
+ })
+ .toMatch(/^(none|matrix\(1, 0, 0, 1, 0, 0\))$/);
+ await expect(dialog).toBeVisible();
+});
+
+/** The sheet's top, once it holds still for 100 ms. */
+async function restingTop(page: Page) {
+ let top = 0;
+ await expect
+ .poll(
+ async () => {
+ const {before, after} = await page.evaluate(async () => {
+ const read = () =>
+ document
+ .querySelector('.astryx-bottom-sheet')
+ ?.getBoundingClientRect().top ?? 0;
+ const first = read();
+ await new Promise(resolve => setTimeout(resolve, 100));
+ return {before: first, after: read()};
+ });
+ top = after;
+ return Math.abs(after - before) < 0.5;
+ },
+ {timeout: 3_000},
+ )
+ .toBe(true);
+ return top;
+}
+
+test('a normal flick from the top snap point stops at the next snap point', async ({
+ page,
+}) => {
+ const {dialog, sheet} = await openSheet(
+ page,
+ 'snap-points',
+ 'Open nearby places',
+ 'Nearby places',
+ );
+ const top = await restingTop(page);
+ const cdp = await page.context().newCDPSession(page);
+ // 60 px in 40 ms is 1,500 px/s: a flick, whose 0.1 s projection lands
+ // short of the half-height snap point.
+ await drag(cdp, sheet, 60, 40);
+ const settled = await restingTop(page);
+ await expect(dialog).toBeVisible();
+ expect(settled - top).toBeGreaterThan(200);
+});
+
+test('a hard flick from the top snap point closes the sheet', async ({
+ page,
+}) => {
+ const {dialog, sheet} = await openSheet(
+ page,
+ 'snap-points',
+ 'Open nearby places',
+ 'Nearby places',
+ );
+ const cdp = await page.context().newCDPSession(page);
+ // 60 px in 6 ms is 10,000 px/s: 0.1 s ahead it lands past the midpoint
+ // between the half-height snap point and closed.
+ await drag(cdp, sheet, 60, 6);
+ await expect(dialog).toBeHidden({timeout: 2_000});
+});
+
+test('a flick from the top snap point whose projection passes the next one closes the sheet', async ({
+ page,
+}) => {
+ const {dialog, sheet} = await openSheet(
+ page,
+ 'snap-points',
+ 'Open nearby places',
+ 'Nearby places',
+ );
+ const top = await restingTop(page);
+ const half = await page.evaluate(() => window.innerHeight * 0.5);
+ const cdp = await page.context().newCDPSession(page);
+ // 60 px in 15 ms is 4,000 px/s. 0.1 s ahead it lands past the
+ // half-height snap point, though nearer it than closed.
+ const projected = top + 60 + 4000 * sheetTable.release.projectionSeconds;
+ expect(projected).toBeGreaterThan(half);
+ expect(projected - half).toBeLessThan(
+ page.viewportSize()!.height - projected,
+ );
+ await drag(cdp, sheet, 60, 15);
+ await expect(dialog).toBeHidden({timeout: 2_000});
+});
+
test('a mouse close under reduced motion moves the sheet no further', async ({
page,
}) => {
@@ -206,6 +385,84 @@ test('a mouse close under reduced motion moves the sheet no further', async ({
expect(between, trace).toEqual([]);
});
+/** A mouse drag on the grabber of `distance` px in `ms`, each event timestamped. */
+async function mouseDrag(
+ cdp: CDPSession,
+ sheet: Locator,
+ distance: number,
+ ms: number,
+) {
+ const box = await sheet.boundingBox();
+ if (box == null) {
+ throw new Error('no sheet box');
+ }
+ const x = box.x + box.width / 2;
+ const y = box.y + 12;
+ const base = Date.now() / 1000;
+ const steps = 6;
+ await cdp.send('Input.dispatchMouseEvent', {
+ type: 'mousePressed',
+ x,
+ y,
+ button: 'left',
+ buttons: 1,
+ clickCount: 1,
+ timestamp: base,
+ });
+ for (let i = 1; i <= steps; i += 1) {
+ await cdp.send('Input.dispatchMouseEvent', {
+ type: 'mouseMoved',
+ x,
+ y: y + (distance * i) / steps,
+ button: 'left',
+ buttons: 1,
+ timestamp: base + (ms * i) / steps / 1000,
+ });
+ }
+ await cdp.send('Input.dispatchMouseEvent', {
+ type: 'mouseReleased',
+ x,
+ y: y + distance,
+ button: 'left',
+ buttons: 0,
+ clickCount: 1,
+ timestamp: base + (ms + 1) / 1000,
+ });
+}
+
+test('a quick short mouse drag keeps the sheet open', async ({page}) => {
+ const {dialog, sheet} = await openFilters(page);
+ const top = await restingTop(page);
+ const cdp = await page.context().newCDPSession(page);
+ // 40 px in 20 ms is 2,000 px/s. The flick is a touch gesture, and a mouse
+ // release this short does not project.
+ await mouseDrag(cdp, sheet, 40, 20);
+ const settled = await restingTop(page);
+ await expect(dialog).toBeVisible();
+ expect(Math.abs(settled - top)).toBeLessThan(1);
+});
+
+test('a faster touch release never stops short of a slower one', async ({
+ page,
+}) => {
+ const settledAfter = async (ms: number) => {
+ const {sheet} = await openSheet(
+ page,
+ 'snap-points-with-peek',
+ 'Open route',
+ 'Route',
+ );
+ await restingTop(page);
+ const cdp = await page.context().newCDPSession(page);
+ await drag(cdp, sheet, 60, ms);
+ return restingTop(page);
+ };
+ // 60 px at about 950 px/s and at about 1,050 px/s, from the top.
+ const slower = await settledAfter(63);
+ const faster = await settledAfter(57);
+ expect(faster).toBeGreaterThanOrEqual(slower - 1);
+});
+
interface CloseWatch {
/** The backdrop's running opacity transition, ms. */
fade: number;
diff --git a/packages/core/src/BottomSheet/useSheetGestures.test.ts b/packages/core/src/BottomSheet/useSheetGestures.test.ts
index af1e6a6ce2..a917aab7f0 100644
--- a/packages/core/src/BottomSheet/useSheetGestures.test.ts
+++ b/packages/core/src/BottomSheet/useSheetGestures.test.ts
@@ -103,7 +103,7 @@ function down(hook: Hook, y: number, t: number, target: HTMLElement) {
hook.result.current.handleProps.onPointerDown(pointerEvent(y, t, target)),
);
}
-/** A touch press on the handle: a drag's close then plays the close spring. */
+/** A touch press on the handle: the release follows UIKit's sheet. */
function touchDown(hook: Hook, y: number, t: number, target: HTMLElement) {
act(() => hook.result.current.sheetRef(target));
act(() =>
@@ -174,16 +174,76 @@ describe('isInsideNestedLayer', () => {
});
describe('useSheetGestures', () => {
- it('dismisses on a fast downward flick (swipe-to-close)', () => {
+ it('closes from the tallest detent on a flick that lands nearer closed than any detent', () => {
const {hook, onDismiss} = setup({snapHeights: () => [200]});
const t = makeTarget();
- down(hook, 0, 0, t);
- // 60px in 20ms = 3px/ms, and 60px > the flick distance floor.
+ touchDown(hook, 0, 0, t);
+ // 60px in 20ms = 3,000 px/s. Projected 0.1 s ahead it lands at 360px,
+ // nearer closed (400px) than the 200px detent.
move(hook, 60, 20, t);
up(hook, 60, 22, t);
expect(onDismiss).toHaveBeenCalledTimes(1);
});
+ it('closes from the tallest detent on a flick whose projection passes the next detent', () => {
+ const {hook, onDismiss} = setup({snapHeights: () => [200]});
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
+ // 60px in 40ms = 1,500 px/s: a flick. Projected 0.1 s ahead it lands at
+ // 210px, past the 200px detent, so it goes on to closed.
+ move(hook, 30, 20, t);
+ move(hook, 60, 40, t);
+ up(hook, 60, 42, t);
+ expect(onDismiss).toHaveBeenCalledTimes(1);
+ });
+
+ it('takes a softer flick from the tallest detent to the next detent down when its projection stops short of it', () => {
+ const onSnap = vi.fn();
+ const {hook, onDismiss} = setup({snapHeights: () => [200], onSnap});
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
+ // 60px in 50ms = 1,200 px/s: a flick. Projected 0.1 s ahead it lands at
+ // 180px, short of the 200px detent, so it goes one position down.
+ move(hook, 30, 25, t);
+ move(hook, 60, 50, t);
+ up(hook, 60, 52, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(onSnap).toHaveBeenLastCalledWith(200);
+ });
+
+ it('keeps a long release under the flick speed from closing a sheet above its lowest detent', () => {
+ const onSnap = vi.fn();
+ const {hook, onDismiss} = setup({snapHeights: () => [200], onSnap});
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
+ // 100px at about 800 px/s: no flick. The sheet stops at the lowest
+ // detent.
+ move(hook, 40, 50, t);
+ move(hook, 80, 100, t);
+ move(hook, 100, 125, t);
+ up(hook, 100, 127, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(onSnap).toHaveBeenLastCalledWith(200);
+ });
+
+ it('closes on a flick at the lowest of two detents', () => {
+ const onSnap = vi.fn();
+ const {hook, onDismiss} = setup({snapHeights: () => [200], onSnap});
+ const t = makeTarget();
+ // Settle on the 200px detent first.
+ touchDown(hook, 0, 0, t);
+ move(hook, 90, 300, t);
+ move(hook, 180, 700, t);
+ up(hook, 180, 1100, t);
+ expect(onSnap).toHaveBeenLastCalledWith(200);
+ // 60px in 40ms = 1,500 px/s from the lowest detent closes the sheet.
+ touchDown(hook, 200, 2000, t);
+ move(hook, 230, 2020, t);
+ move(hook, 260, 2040, t);
+ up(hook, 260, 2042, t);
+ expect(onDismiss).toHaveBeenCalledTimes(1);
+ });
+
it('settles instead of dismissing on a downward flick when canDismiss is false', () => {
const onSnap = vi.fn();
const onScrimOpacity = vi.fn();
@@ -310,15 +370,175 @@ describe('useSheetGestures', () => {
});
});
- it('does not flick-dismiss on a fast but short nudge', () => {
- const {hook, onDismiss} = setup({snapHeights: () => [200]});
+ it('takes a fast short flick from the tallest of two detents to the next one down', () => {
+ const onSnap = vi.fn();
+ const {hook, onDismiss} = setup({snapHeights: () => [200], onSnap});
const t = makeTarget();
- // Fast (20px/10ms = 2px/ms) but only 20px of travel — under the distance
- // floor, so nothing is projected and it settles rather than dismissing.
- down(hook, 0, 0, t);
+ // 20px in 16ms = 1,250 px/s, a flick. Its 0.1 s projection lands at
+ // 145px, short of the 200px detent. A flick goes at least one position
+ // down: the 200px detent.
+ touchDown(hook, 0, 0, t);
+ move(hook, 20, 16, t);
+ up(hook, 20, 18, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(onSnap).toHaveBeenLastCalledWith(200);
+ });
+
+ it('closes on a fast short flick at the lowest detent', () => {
+ const {hook, onDismiss} = setup(); // one detent: fully open
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
move(hook, 20, 10, t);
up(hook, 20, 12, t);
+ expect(onDismiss).toHaveBeenCalledTimes(1);
+ });
+
+ it('keeps a short release under the flick speed', () => {
+ const {hook, onDismiss} = setup();
+ const t = makeTarget();
+ // 20px in 25ms = 800 px/s: below the flick speed, so it settles back.
+ touchDown(hook, 0, 0, t);
+ move(hook, 20, 25, t);
+ up(hook, 20, 27, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(hook.result.current.settledOffset).toBe(0);
+ });
+
+ it('expands to the next detent up on a fast short flick', () => {
+ const onSnap = vi.fn();
+ const {hook} = setup({snapHeights: () => [200], onSnap});
+ const t = makeTarget();
+ // Settle on the 200px detent first.
+ touchDown(hook, 0, 0, t);
+ move(hook, 90, 300, t);
+ move(hook, 180, 700, t);
+ up(hook, 180, 1100, t);
+ expect(onSnap).toHaveBeenLastCalledWith(200);
+ touchDown(hook, 400, 2000, t);
+ move(hook, 380, 2010, t);
+ up(hook, 380, 2012, t);
+ expect(onSnap).toHaveBeenLastCalledWith(400);
+ });
+
+ it('hands the panel the distance left and the release speed after a drag closes it', () => {
+ const {hook, onDismiss} = setup();
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
+ move(hook, 20, 10, t);
+ // The host takes the close in the same update, as a controlled host does.
+ act(() => {
+ hook.result.current.handleProps.onPointerUp(pointerEvent(20, 12, t));
+ hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
+ });
+ expect(onDismiss).toHaveBeenCalledTimes(1);
+ // 380px left to travel, at the release's 2,000 px/s.
+ expect(hook.result.current.dragExit).toEqual({
+ distance: 380,
+ velocity: 2000,
+ });
+ });
+
+ it('keeps the stylesheet exit for a close that no drag started', () => {
+ const {hook, onDismiss} = setup();
+ hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
+ expect(hook.result.current.dragExit).toBeNull();
+ });
+
+ it('springs a quick short mouse drag back at the lowest detent', () => {
+ const {hook, onDismiss} = setup(); // one detent: fully open
+ const t = makeTarget();
+ // 40 px in 20 ms = 2,000 px/s with a mouse. The flick is a touch gesture,
+ // and 40 px is too short to project.
+ down(hook, 0, 0, t);
+ move(hook, 20, 10, t);
+ move(hook, 40, 20, t);
+ up(hook, 40, 22, t);
expect(onDismiss).not.toHaveBeenCalled();
+ expect(hook.result.current.settledOffset).toBe(0);
+ });
+
+ it('gives a mouse drag that closes the sheet the stylesheet exit', () => {
+ const {hook, onDismiss} = setup();
+ const t = makeTarget();
+ down(hook, 0, 0, t);
+ move(hook, 100, 50, t);
+ move(hook, 200, 100, t);
+ act(() => {
+ hook.result.current.handleProps.onPointerUp(pointerEvent(200, 102, t));
+ hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
+ });
+ expect(onDismiss).toHaveBeenCalledTimes(1);
+ expect(hook.result.current.dragExit).toBeNull();
+ });
+
+ it('never stops a faster touch release short of a slower one', () => {
+ // Detents at 0, 200 and 340 px; closed at 400 px.
+ const land = (ms: number) => {
+ const {hook} = setup({snapHeights: () => [200, 60]});
+ const t = makeTarget();
+ touchDown(hook, 0, 0, t);
+ move(hook, 30, ms / 2, t);
+ move(hook, 60, ms, t);
+ up(hook, 60, ms + 2, t);
+ return hook.result.current.settledOffset;
+ };
+ // 60 px at 1,000 px/s and at 1,091 px/s. Both land 0.1 s ahead, nearest
+ // the 200 px detent.
+ expect(land(60)).toBe(200);
+ expect(land(55)).toBe(200);
+ });
+
+ it('closes the sheet on a slow touch drag only past halfway from the lowest detent to closed', () => {
+ const drag = (to: number) => {
+ const {hook, onDismiss} = setup({snapHeights: () => [200]});
+ const t = makeTarget();
+ // Settle on the 200 px detent first.
+ touchDown(hook, 0, 0, t);
+ move(hook, 90, 300, t);
+ move(hook, 180, 700, t);
+ up(hook, 180, 1100, t);
+ // Then a slow drag down at 225 px/s, too slow to project, in ten even
+ // steps.
+ touchDown(hook, 200, 2000, t);
+ const step = (to - 200) / 10;
+ for (let i = 1; i <= 10; i += 1) {
+ move(hook, 200 + step * i, 2000 + (step / 0.225) * i, t);
+ }
+ up(hook, to, 2000 + (step / 0.225) * 10 + 2, t);
+ return onDismiss.mock.calls.length;
+ };
+ // Closed is at 400 px, so halfway from the 200 px detent is 300 px.
+ expect(drag(290)).toBe(0);
+ expect(drag(310)).toBe(1);
+ });
+
+ it('cancels a touch release thrown back toward where the drag began', () => {
+ const {hook, onDismiss} = setup(); // one detent; closed at 400 px
+ const t = makeTarget();
+ // Slowly most of the way down, then 30 px back up at 1,000 px/s. Its
+ // landing (230 px) is past halfway to closed, but it moves back.
+ touchDown(hook, 0, 0, t);
+ for (let i = 1; i <= 9; i += 1) {
+ move(hook, i * 40, i * 200, t);
+ }
+ move(hook, 345, 1815, t);
+ move(hook, 330, 1830, t);
+ up(hook, 330, 1832, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(hook.result.current.settledOffset).toBe(0);
+ });
+
+ it("springs a gentle touch throw back where UIKit's sheet does", () => {
+ const {hook, onDismiss} = setup({snapHeights: () => [200]});
+ const t = makeTarget();
+ // 60 px at 300 px/s lands 0.1 s ahead at 90 px, nearer the 0 px detent
+ // than the 200 px one.
+ touchDown(hook, 0, 0, t);
+ move(hook, 30, 100, t);
+ move(hook, 60, 200, t);
+ up(hook, 60, 202, t);
+ expect(onDismiss).not.toHaveBeenCalled();
+ expect(hook.result.current.settledOffset).toBe(0);
});
it('settles to the nearest detent on a slow drag', () => {
@@ -653,47 +873,6 @@ describe('useSheetGestures', () => {
expect(onDismiss).not.toHaveBeenCalled();
});
- describe("a drag's close", () => {
- it('hands the panel the distance left and the release speed after a touch drag closes it', () => {
- const {hook, onDismiss} = setup();
- const t = makeTarget();
- touchDown(hook, 0, 0, t);
- move(hook, 100, 50, t);
- move(hook, 200, 100, t);
- // The host takes the close in the same update, as a controlled host does.
- act(() => {
- hook.result.current.handleProps.onPointerUp(pointerEvent(200, 102, t));
- hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
- });
- expect(onDismiss).toHaveBeenCalledTimes(1);
- // 200px left to travel, at the release's 2,000 px/s.
- expect(hook.result.current.dragExit).toEqual({
- distance: 200,
- velocity: 2000,
- });
- });
-
- it('keeps the stylesheet exit for a close that no drag started', () => {
- const {hook, onDismiss} = setup();
- hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
- expect(hook.result.current.dragExit).toBeNull();
- });
-
- it('gives a mouse drag that closes the sheet the stylesheet exit', () => {
- const {hook, onDismiss} = setup();
- const t = makeTarget();
- down(hook, 0, 0, t);
- move(hook, 100, 50, t);
- move(hook, 200, 100, t);
- act(() => {
- hook.result.current.handleProps.onPointerUp(pointerEvent(200, 102, t));
- hook.rerender({isOpen: false, isOpenRequested: false, onDismiss});
- });
- expect(onDismiss).toHaveBeenCalledTimes(1);
- expect(hook.result.current.dragExit).toBeNull();
- });
- });
-
describe('pinch', () => {
// A second finger is a pinch, and pinch-zoom belongs to the browser.
it('declares pinch-zoom on the sliding surface and the handle', () => {
diff --git a/packages/core/src/BottomSheet/useSheetGestures.ts b/packages/core/src/BottomSheet/useSheetGestures.ts
index 5cb66230b9..e93d56a5ea 100644
--- a/packages/core/src/BottomSheet/useSheetGestures.ts
+++ b/packages/core/src/BottomSheet/useSheetGestures.ts
@@ -64,8 +64,10 @@ import {
type UIEvent as ReactUIEvent,
} from 'react';
+import {resolveSnapPoint} from '../motion/resolveSnapPoint';
import {rubberBand} from '../motion/rubberBand';
import {scroll} from '../motion/uikit/scroll';
+import {sheet} from '../motion/uikit/sheet';
import {
computeDetentOffsets,
peekOffsetFor,
@@ -1217,17 +1219,45 @@ export function useSheetGestures({
setTouchDragDismissal({isTouch, pending: true, exit});
onDismissRef.current();
};
+ if (isTouch) {
+ // A touch release takes UIKit's sheet values, with closed counted as
+ // one position. A flick lands on the first position at or past its
+ // projection. A release that moves back toward where the drag began
+ // cancels to that detent.
+ const {
+ fastSpeed,
+ minProjectionSpeed,
+ projectionSeconds,
+ detentTolerance,
+ } = sheet.release;
+ const points = [...offsets, maxOffset + shortestDetentHeight];
+ const {index} = resolveSnapPoint({
+ points,
+ position: offset,
+ velocity: velocity * 1000,
+ flickThreshold: travel > DRAG_PROMOTION_SLOP ? fastSpeed : Infinity,
+ tolerance: detentTolerance,
+ flickPastProjection: true,
+ projection: {
+ seconds: projectionSeconds,
+ minSpeed: minProjectionSpeed,
+ },
+ start: baseOffset,
+ });
+ if (index === points.length - 1) {
+ closeSheet({
+ distance: Math.max(0, height - offset),
+ velocity: velocity * 1000,
+ });
+ } else {
+ settleAt(points[index]);
+ }
+ return;
+ }
// A release that would coast past the dismiss line closes the sheet: a
// throw from anywhere, or a slow drag that already crossed it.
if (dir > 0 && projected > dismissOffset) {
- closeSheet(
- isTouch
- ? {
- distance: Math.max(0, height - offset),
- velocity: velocity * 1000,
- }
- : null,
- );
+ closeSheet(null);
return;
}
// Settle to the detent nearest where the release would coast to, in the
diff --git a/packages/core/src/motion/README.md b/packages/core/src/motion/README.md
index 164edfb9f6..5d7cec1464 100644
--- a/packages/core/src/motion/README.md
+++ b/packages/core/src/motion/README.md
@@ -26,6 +26,7 @@ roles through `resolveMotion`.
| `uikit/gestures.ts` | Gesture recognizer thresholds, the velocity filter and haptic stand-ins, as `{value, unit}` entries (sources in JSDoc). |
| `uikit/picker.ts` | UIPickerView: row pitch, height and rubber band, velocity floor, the coast's stop speed, snap at rest, tap spin, tick. |
| `uikit/segmented.ts` | UISegmentedControl: the selection indicator's spring; under Reduce Motion the animator's cross-fade replaces it. |
+| `uikit/sheet.ts` | UISheetPresentationController: the flick speed, how near a detent counts as on it, how far ahead a release is projected, and the speed below which it is not. |
| `uikit/switch.ts` | UISwitch on iOS 26.2: geometry, the lift, settle, travel and tracking springs, the flip distance, the track colour. |
| `uikit/datePicker.ts` | UIDatePicker: the rules it adds to its wheels. |
| `android/keyboard.ts` | Android's software keyboard (Chrome with Gboard): its slides' durations and curves (no theme's) and when they start against Chrome's report and a blur. |
diff --git a/packages/core/src/motion/resolveSnapPoint.test.ts b/packages/core/src/motion/resolveSnapPoint.test.ts
index 742291cee1..3f62ff031d 100644
--- a/packages/core/src/motion/resolveSnapPoint.test.ts
+++ b/packages/core/src/motion/resolveSnapPoint.test.ts
@@ -86,6 +86,38 @@ describe('resolveSnapPoint', () => {
).toBe(1);
});
+ it('with flickPastProjection, takes a flick to the first snap point at or past its projection', () => {
+ const past = (position: number, velocity: number) =>
+ resolveSnapPoint({
+ ...SHEET,
+ points: [0, 200, 400],
+ position,
+ velocity,
+ flickPastProjection: true,
+ }).index;
+ // Projected 210: past 200, so on to 400.
+ expect(past(60, 1500)).toBe(2);
+ // Projected 180: short of 200, so the next snap point, 200.
+ expect(past(60, 1200)).toBe(1);
+ // Projected exactly onto 200: it lands there.
+ expect(past(80, 1200)).toBe(1);
+ // Projected past the last snap point: the last.
+ expect(past(60, 5000)).toBe(2);
+ // Moving down the axis: projected 190 from 340, past 200, so on to 0.
+ expect(past(340, -1500)).toBe(0);
+ // A slow release keeps the nearest snap point to its projection.
+ expect(past(60, 800)).toBe(1);
+ // Without the option, the projection's nearest snap point stays (200).
+ expect(
+ resolveSnapPoint({
+ ...SHEET,
+ points: [0, 200, 400],
+ position: 60,
+ velocity: 1500,
+ }).index,
+ ).toBe(1);
+ });
+
it('counts a snap point within the tolerance as reached, so a flick goes on to the one after it', () => {
expect(
resolveSnapPoint({
diff --git a/packages/core/src/motion/resolveSnapPoint.ts b/packages/core/src/motion/resolveSnapPoint.ts
index b23f5bdbd1..60e45e265a 100644
--- a/packages/core/src/motion/resolveSnapPoint.ts
+++ b/packages/core/src/motion/resolveSnapPoint.ts
@@ -24,7 +24,9 @@
* beyond its position in the direction it moves, or on the nearest
* snap point to its projection if that is farther. A snap point within
* `tolerance` of the position counts as reached, so the flick goes on to
- * the one after it.
+ * the one after it. With `flickPastProjection`, a flick lands on the first
+ * snap point at or past its projection instead. A projection that passes a
+ * snap point carries the flick on.
* - With `start` (where the drag began), a release moving back toward it
* cancels to the snap point nearest `start`, whatever its travel so far or its
* speed.
@@ -99,6 +101,7 @@ export function resolveSnapPoint({
velocity,
flickThreshold,
tolerance = 0,
+ flickPastProjection = false,
projection,
start,
fromIndex,
@@ -112,6 +115,8 @@ export function resolveSnapPoint({
flickThreshold: number;
/** A snap point this close to the position counts as reached by a flick. */
tolerance?: number;
+ /** A flick lands on the first snap point at or past its projection. */
+ flickPastProjection?: boolean;
/** Judge a slow release where it would coast to; absent, where it was let go. */
projection?: SnapPointProjection;
/** Where the drag began: a release moving back toward it cancels to it. */
@@ -152,6 +157,26 @@ export function resolveSnapPoint({
if (next !== -1 && (velocity > 0 ? next > index : next < index)) {
index = next;
}
+ if (flickPastProjection) {
+ // The first snap point at or past the projection in the flick's
+ // direction, or the last one there when the projection passes them all.
+ const projected = choice.projected;
+ let past = velocity > 0 ? points.length - 1 : 0;
+ if (velocity > 0) {
+ const at = points.findIndex(d => d >= projected - tolerance);
+ past = at === -1 ? past : at;
+ } else {
+ for (let i = points.length - 1; i >= 0; i -= 1) {
+ if (points[i] <= projected + tolerance) {
+ past = i;
+ break;
+ }
+ }
+ }
+ if (velocity > 0 ? past > index : past < index) {
+ index = past;
+ }
+ }
}
if (
start != null &&
diff --git a/packages/core/src/motion/uikit/index.ts b/packages/core/src/motion/uikit/index.ts
index 47ae030d08..b75b5db1ec 100644
--- a/packages/core/src/motion/uikit/index.ts
+++ b/packages/core/src/motion/uikit/index.ts
@@ -6,9 +6,9 @@
* @output Re-exports `springs` and one constant per spring
* (`SHEET_PRESENT_SPRING`, …), and the `scroll`, `timing`, `navigation`,
* `picker`, `popover`, `progressBar`, `segmentedControl`, `datePicker`,
- * `slider`, `switchControl` and `zoomMedia` domains. It also re-exports the
- * gesture thresholds: one `UIKIT_*` group per recognizer, their union
- * `UIKIT_GESTURES`, and the haptic tables
+ * `sheet`, `slider`, `switchControl` and `zoomMedia` domains. It also
+ * re-exports the gesture thresholds: one `UIKIT_*` group per recognizer,
+ * their union `UIKIT_GESTURES`, and the haptic tables
* @position Entry of the UIKit constants table (motion/uikit). Internal to
* core: not exported from the package entry point
*
@@ -48,6 +48,7 @@ export {popover} from './popover';
export {progressBar, registerProgressBarTable} from './progressBar';
export {registerScrollTable, scroll} from './scroll';
export {segmentedControl} from './segmented';
+export {sheet} from './sheet';
export {slider} from './slider';
export {
ACTION_SHEET_DISMISS_SPRING,
diff --git a/packages/core/src/motion/uikit/sheet.ts b/packages/core/src/motion/uikit/sheet.ts
new file mode 100644
index 0000000000..f931cb0b44
--- /dev/null
+++ b/packages/core/src/motion/uikit/sheet.ts
@@ -0,0 +1,76 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file sheet.ts
+ * @input Nothing; data only
+ * @output Exports `sheet`, the sheet's release constants. They say when
+ * UISheetPresentationController counts a release as a flick and how near a
+ * detent a flick counts as on it. They also give how far ahead a release is
+ * projected, and the speed below which it is not
+ * @position The sheet domain of the UIKit constants table (motion/uikit).
+ * Its springs are `springs.sheetPresent`, `.sheetDismiss`, `.sheetDetent`,
+ * `.sheetReleaseFast` and `.sheetDismissSwipe`
+ *
+ * Read from UIKit with a `[.medium(), .large()]` sheet in an injected host
+ * app. Speeds are in pt/s (CSS px/s).
+ *
+ * SYNC: When modified, update /packages/core/src/motion/README.md
+ */
+
+export const sheet = {
+ release: {
+ /**
+ * Release speed (pt/s, in either direction) from which UIKit's sheet
+ * counts a release as a flick. A sheet's flick goes at least to the next
+ * position beyond where it is in its direction (`detentTolerance`). It
+ * goes on past it when its projection passes it. The same speed
+ * switches UIKit's settle from `springs.sheetDetent` (critically damped)
+ * to `springs.sheetReleaseFast` (80 % damping). An interactive dismissal
+ * at it takes `springs.sheetDismissSwipe`. Inside the measured bracket.
+ * @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
+ * iPhone 17 Pro, Oct 23 and Oct 24 2026. Of 134 drag releases, 55 had
+ * their CASpringAnimation read. Every one up to 996.7 pt/s had damping
+ * 36.515 (ζ 1), and every one from 1028.3 pt/s on had 29.212 (ζ 0.8).
+ * So the switch lies in (996.7, 1028.3]. With a 0.1 s projection, all
+ * 134 outcomes fit a flick threshold from 997 to 1028 pt/s.
+ */
+ fastSpeed: 1008,
+ /**
+ * How far ahead a release is projected, as seconds of its velocity.
+ * UIKit's sheet projects a release to `offset + velocity × this`, and the
+ * dismissed position (fully off screen) counts as one of its positions.
+ * A slow release settles on the position nearest this landing. A flick
+ * goes to the first position at or past it. Inside the measured bracket.
+ * @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
+ * iPhone 17 Pro, Oct 23 to Oct 25 2026. There were 164 drag releases
+ * of a [.medium(), .large()] sheet, from 0 to 4000 pt/s. Each gave the
+ * offset and velocity of its last drag update and the detent it
+ * settled on. With `fastSpeed`'s flick branch and no projection below
+ * 250 pt/s, every release fits any value from 0.092 to 0.104 s.
+ */
+ projectionSeconds: 0.1,
+ /**
+ * Release speed (pt/s) below which a release is not projected: the sheet
+ * settles on the position nearest where it was let go. Core cancels a
+ * release that moves back toward its start before this applies. Inside
+ * the measured bracket.
+ * @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
+ * iPhone 17 Pro, Oct 25 2026. There were 30 releases of drags from the
+ * medium detent. Each went past the midpoint toward large, or most of
+ * the way to gone, then turned back. Each one let go at up to 244 pt/s
+ * settled on the position nearest where it was let go. From 250.6 pt/s
+ * on, the projection decided. So the switch lies in (244, 250.6].
+ */
+ minProjectionSpeed: 250,
+ /**
+ * How close to a position (pt) a flick's offset counts as on it, so the
+ * next position beyond is the one after it. Inside the measured bracket.
+ * @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
+ * iPhone 17 Pro, Oct 24 2026. Two flicks released exactly on the medium
+ * detent went on to the next position in their direction. One released
+ * 6.7 pt above it, moving down, stopped at medium. So any value from 0
+ * to 6.6 pt fits.
+ */
+ detentTolerance: 1,
+ },
+} as const;