Repository navigation
feat(Toast): the swipe follows iOS notification banners under a finger #8121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vjeux
wants to merge
19
commits into
meta:main
Choose a base branch
from
vjeux:uikit/c25-toast-swipe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,255
−340
Draft
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1f6596e
feat(Toast): the swipe follows iOS notification banners under a finger
vjeux 800a0db
docs(specs): name Toast's touch layer in its record
vjeux 4e842ab
fix(Toast): a finger catches the card mid-motion
vjeux 1a80fef
fix(Toast): a card dismissed mid-drag still leaves; report it at once
vjeux 7ac4d46
fix(Toast): every exit under a finger plays the banner slide
vjeux 07e139f
Merge main
vjeux cee63c3
docs(Toast): the exit decision also covers a swipe's commit
vjeux d3aae65
refactor(Toast): read the latest props through useCommittedRef
vjeux b4ae127
refactor(Toast): store the dismissal through useCommittedRefInto
vjeux 9c15f0e
fix(Toast): leave a toast's entrance to a tap
vjeux 54309a8
docs(specs): FR4 and FR38 name Toast's exit exception
vjeux 1591f6f
Merge main
vjeux 7127377
docs(specs): FR7 and Toast FR4 match the exit and second-touch rules
vjeux 407c161
Merge main
vjeux 48bfd6a
fix(Toast): let a finger take an entering card from where it shows
vjeux 270bd41
fix(Toast): fade a dismissal during the entrance from where it shows
vjeux ad73222
Merge main
vjeux 0a6be9d
Merge main
vjeux 496e170
Merge main
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/caseIds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
53
apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/cases.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
62
apps/sandbox/src/app/(raw)/pages/toast-swipe-cases/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.