Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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/toast-swipe-follows-banner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feat] Under a finger (a coarse primary pointer), a Toast now follows iOS notification banners. The card stays still for the first 14 px of finger travel and then follows at 0.55 of the finger, with no jump. A swipe that turns back away from the toast's edge stretches the card that way and springs it back. On release, a quick flick toward the edge dismisses even when it barely moved the card, as does a drag that leaves the card far enough out; anything else springs the card back. However a toast is dismissed (a swipe, the close button, the timeout, the app's dismiss), the card leaves as the banner does: it slides past its edge from where it is, without fading, and its row closes after it. A finger that lands on the card while it springs back or leaves catches it, and the card follows the finger. Before, a toast under a finger moved with the finger as it faded and shrank, and faded out when dismissed. With a fine pointer nothing changes. Under reduced motion nothing slides, springs or drifts: under a finger (a coarse primary pointer) the toast fades in place, and with a mouse or keyboard it changes at once.

@vjeux
1 change: 1 addition & 0 deletions apps/sandbox/scripts/next-export-routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"/pages/text-types/",
"/pages/textarea-counter/",
"/pages/theme-family/",
"/pages/toast-swipe-cases/",
"/pages/topnav-menu/",
"/pages/y2k-palette/",
"/templates/",
Expand Down
35 changes: 35 additions & 0 deletions apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/caseIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file caseIds.ts
* @input None
* @output The Toast swipe case ids, their labels, and the parser for `?case=`
* @position Shared by the Toast swipe cases page and its cases.
*
* SYNC: A new case needs a toast body in cases.tsx.
*/

export const TOAST_SWIPE_CASES = [
'swipe-away',
'turn-back',
'pull-away',
] as const;

export type ToastSwipeCaseId = (typeof TOAST_SWIPE_CASES)[number];

export const TOAST_SWIPE_CASE_LABELS: Readonly<
Record<ToastSwipeCaseId, string>
> = {
'swipe-away':
'Swipe a top toast up and away. A short drag springs it back; a quick flick or a longer drag sends it off the top',
'turn-back':
'Drag the toast up, then move back down before you lift. A release that moves back springs the card back',
'pull-away':
'Drag the toast up a little, then pull it down past where it started. The card stretches down and springs back',
};

export function parseToastSwipeCase(value: string | null): ToastSwipeCaseId {
return (TOAST_SWIPE_CASES as readonly string[]).includes(value ?? '')
? (value as ToastSwipeCaseId)
: TOAST_SWIPE_CASES[0];
}
53 changes: 53 additions & 0 deletions apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/cases.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
* @file cases.tsx
* @input A case id from caseIds.ts
* @output The case: a top toast to swipe up and away, to turn back, or to
* pull past where it started
* @position The Toast swipe cases page's content.
*/

import {useEffect, useRef} from 'react';
import {Button} from '@astryxdesign/core/Button';
import {ToastViewport, useToast} from '@astryxdesign/core/Toast';
import type {ToastDismissFn} from '@astryxdesign/core/Toast';
import type {ToastSwipeCaseId} from './caseIds';

const BODIES: Readonly<Record<ToastSwipeCaseId, string>> = {
'swipe-away': 'Swipe this toast up and away.',
'turn-back': 'Drag this toast up, then back down before you lift.',
'pull-away':
'Drag this toast up a little, then pull it down past where it started.',
};

function ShowToast({id}: {id: ToastSwipeCaseId}) {
const toast = useToast();
// The case's one toast. Showing it again replaces it.
const dismissRef = useRef<ToastDismissFn | null>(null);
// Synchronizes the toast system with the case: leaving the case dismisses
// its toast.
useEffect(() => () => dismissRef.current?.(), []);
return (
<Button
label="Show the toast"
onClick={() => {
dismissRef.current = toast({
body: BODIES[id],
uniqueID: 'toast-swipe-case',
isAutoHide: false,
});
}}
/>
);
}

export function ToastSwipeCase({id}: {id: ToastSwipeCaseId}) {
return (
<ToastViewport position="topEnd">
<ShowToast id={id} />
</ToastViewport>
);
}
62 changes: 62 additions & 0 deletions apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
* @file page.tsx
* @input `?case=` (one of the ids in caseIds.ts; the first by default)
* @output A bare page with one Toast swipe case above rows that make the
* document scroll
* @position A raw page, with no sandbox chrome, for checking the cases on a
* phone. The page scrolls with the document, as an app's page does.
*/

import {Suspense} from 'react';
import {useSearchParams} from 'react-router-dom';
import {HStack, VStack} from '@astryxdesign/core/Layout';
import {Link} from '@astryxdesign/core/Link';
import {Heading, Text} from '@astryxdesign/core/Text';
import {ToastSwipeCase} from './cases';
import {
parseToastSwipeCase,
TOAST_SWIPE_CASE_LABELS,
TOAST_SWIPE_CASES,
} from './caseIds';

const ROWS = Array.from({length: 40}, (_, index) => `Row ${index + 1}`);

function ToastSwipeCases() {
const [searchParams] = useSearchParams();
const id = parseToastSwipeCase(searchParams.get('case'));
return (
<VStack gap={4} padding={4}>
<VStack gap={1}>
<Heading level={1}>Toast swipe cases</Heading>
<Text color="secondary">{TOAST_SWIPE_CASE_LABELS[id]}</Text>
<HStack gap={3}>
{TOAST_SWIPE_CASES.map(caseId => (
<Link key={caseId} href={`?case=${caseId}`}>
{caseId}
</Link>
))}
</HStack>
</VStack>
<ToastSwipeCase key={id} id={id} />
<VStack gap={2}>
{ROWS.map(row => (
<Text key={row} color="secondary">
{row}
</Text>
))}
</VStack>
</VStack>
);
}

export default function ToastSwipeCasesPage() {
return (
<Suspense>
<ToastSwipeCases />
</Suspense>
);
}
6 changes: 6 additions & 0 deletions apps/sandbox/src/app/sandboxPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export const categories: SandboxCategory[] = [
description:
'A full page ChatLayout for phone checks. ?case= long (the default), composer or streaming scroll the document; docked scrolls a fixed-height panel',
},
{
name: 'Toast Swipe Cases',
href: '/pages/toast-swipe-cases/',
description:
'A top toast to swipe away, turn back or pull past where it started, on a page that scrolls with the document, to check on a phone',
},
{
name: 'AlertDialog Cases',
href: '/pages/alert-dialog-cases/',
Expand Down
5 changes: 3 additions & 2 deletions apps/sandbox/src/hydration-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @output Whether React can safely hydrate instead of client-rendering.
* @position Prevents mismatches for iframe themes and for pages whose first
* render reads URL controls. Those pages are Shell Lab, Perf Scenes, Chat
* Layout, AlertDialog Cases, List Reorder Cases, Scroll Edge Taps and Swipe
* Actions Cases.
* Layout, AlertDialog Cases, Toast Swipe Cases, List Reorder Cases, Scroll
* Edge Taps and Swipe Actions Cases.
*/

/** Pages whose first render reads the query string. */
Expand All @@ -16,6 +16,7 @@ const QUERY_RENDERED_PAGES = new Set([
'/pages/perf-scenes/',
'/pages/chat-layout/',
'/pages/alert-dialog-cases/',
'/pages/toast-swipe-cases/',
'/pages/list-reorder-cases/',
'/pages/scroll-edge-taps/',
'/pages/swipe-actions-cases/',
Expand Down
4 changes: 4 additions & 0 deletions apps/sandbox/src/route-manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ describe('Sandbox static export contract', () => {
canHydrate('/pages/alert-dialog-cases/', '?case=alert-over-a-toast'),
).toBe(false);
expect(canHydrate('/pages/alert-dialog-cases/', '')).toBe(true);
expect(canHydrate('/pages/toast-swipe-cases/', '?case=turn-back')).toBe(
false,
);
expect(canHydrate('/pages/toast-swipe-cases/', '')).toBe(true);
expect(canHydrate('/pages/list-reorder-cases/', '?case=list')).toBe(false);
expect(canHydrate('/pages/list-reorder-cases/', '')).toBe(true);
expect(canHydrate('/pages/scroll-edge-taps/', '?case=refresh')).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/stories/Toast.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export const MobileSwipeToDismiss: StoryObj = {
render: () => (
<MobileCanvas
title="Swipe dismissal"
description="Swipe is an enhancement only; the surface fades as it approaches the edge, and the visible close button remains the simple alternative.">
description="Swipe is an enhancement only. Under a finger, as with iOS notification banners, the card follows the finger after a short distance at about half its speed, a quick flick dismisses it, and it leaves by sliding past its edge; with a pen on a desktop the surface fades as it approaches the edge. The visible close button remains the simple alternative.">
<ToastViewport position="topEnd" isTopLayer={false} maxVisible={2}>
<MockCard>
<Text type="supporting" color="secondary">
Expand Down
32 changes: 21 additions & 11 deletions docs/specs/AST-094-touch-presentations/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ a measured, sourced difference exists.
its use (`architecture:theme-tokens` INV3), with one exception. A
gesture-driven exit (a release that closes or dismisses) may play a spring
measured from the platform reference without a named motion role (FR45); its
component's motion table lists that spring with its platform source. Every
other gesture-driven motion plays a motion role. The roles this record names
component's motion table lists that spring with its platform source. Toast's
exit under a finger plays a measured curve instead (FR45, `component:Toast`
DEC-2). Every other gesture-driven motion plays a motion role.
The roles this record names
are listed below with their defaults and sources; further roles a component's
own record measures join through the generated motion role table (DEC-5). With
tempo 1 and character standard, every role plays its measured value exactly
Expand Down Expand Up @@ -316,7 +318,8 @@ a measured, sourced difference exists.
platform: a menu shrinks into its trigger, and an alert fades. In a component
whose main interaction is a tap, an exit that a tap, a key, an outside press
or the program starts plays the theme's exit duration and easing,
`--duration-exit` and `--ease-exit` (`spec:AST-090` FR14, FR45). A component
`--duration-exit` and `--ease-exit` (`spec:AST-090` FR14, FR45). Toast's exit
under a finger is FR45's exception (`component:Toast` DEC-2). A component
whose main interaction is a gesture, such as a sheet or the Lightbox, plays
every exit on its spring: a close that a tap, a key, an outside press or the
program starts plays the same settle as a swipe close, from rest, and an exit
Expand Down Expand Up @@ -402,11 +405,13 @@ a measured, sourced difference exists.
| Gesture | Springs: a tap, key or program turn plays `springs.settle` from rest; the flick coast keeps UIKit's measured deceleration; the slow-release snap stays as recorded | the DateInput and TimeInput wheels |
| Tap | Curve tokens | Accordion, Disclosure, Collapsible, DropdownMenu, Popover, Tooltip, HoverCard, Dialog, AlertDialog, Tabs, Checkbox, press feedback |
| Gesture-capable | Springs under a touch presentation: the thumb drags, so every tap, click, key or value change settles on the same spring; without a touch presentation they keep the theme's curve (owner decision, 2026-11-04) | Switch, SegmentedControl |
| Open (as its record states today) | Theme timing for a tap dismiss; a spring from the release for a swipe | Toast |
| Exception, under a finger (Toast) | Under a finger every exit, a tap dismiss too, plays the banner's measured slide, also in place of a swipe commit's FR38 spring and FR4 role; a fine pointer keeps the theme's fade (`component:Toast` DEC-2) | Toast |

Toast keeps the motion its record states today: theme timing for a tap
dismiss, and a spring from the release for a swipe (`component:Toast` FR5).
Which main interaction classifies it is open.
Toast is the exception: under a finger every exit plays the notification
banner's measured slide, a tap dismiss included, and a fine pointer keeps
the theme's fade. For a swipe's commit the slide also takes the place of
FR38's tempo-scaled spring and FR4's named motion role (`component:Toast`
DEC-2).

| Spring roles | Timing tier |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
Expand Down Expand Up @@ -736,15 +741,20 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
detent closes it (`component:BottomSheet` FR19). When the owner refuses the
close and opens a confirmation dialog in answer, the sheet waits at a peek
until the dialog closes instead of springing back (`component:BottomSheet`
FR21). A row swipe keeps
`spec:AST-057`'s own release rule.
FR21). A Toast's touch release takes the notification banner's measured
values, the UIKit table's Toast domain. Its projection is 0, and its commit
point is 15.7 px out. A release past its measured flick speed, 105 px/s
toward the edge from at or past rest, commits (`component:Toast` FR4). 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.
- **FR38 — The settle continues the pointer.** The commit or the spring-back
MUST start at the release velocity (FR6), under every pointer (FR43), on a
spring whose duration the theme's `tempo` scales and whose measured bounce
its `character` offsets by the role's fixed weight (FR45). Under reduced motion it follows `design:reduced-motion` DR2, and a
release from a mouse, a trackpad or a pen follows FR43.
its `character` offsets by the role's fixed weight (FR45). Toast's commit
under a finger is FR45's exception (`component:Toast` DEC-2). Under reduced
motion it follows `design:reduced-motion` DR2, and a release from a mouse, a
trackpad or a pen follows FR43.
- **FR39 — The action never needs a drag.** Every action a drag commits MUST
also be reachable without a drag, by keyboard and by mouse
(`architecture:interaction-modality` INV4).
Expand Down
Loading