Toast
Compact status notifications with an icon, title, detail and close control at either safe-area edge.
npx @swipeui/cli add toastWhen to use it
- Brief non-blocking status feedback; use Snackbar for one application action and Dialog for decisions.
When not to use it
- Errors that need attention on a specific screen. Use Alert.
- Decisions. Use Dialog.
- Long messages or several actions.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add toast- Adds
components/swipeui/ui/use-toast-gesture.ts,components/swipeui/ui/toast.tsx,components/swipeui/ui/toast-icon.tsx,components/swipeui/ui/toast-details.tsxand 11 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-safe-area-context, react-native-svg, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ToastHost, ToastProvider } from '@/components/swipeui/ui/toast';
<ToastProvider>
<Slot />
<ToastHost />
</ToastProvider>;Examples
Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.
The toast uses a content-sized, borderless card with a raised shadow, capped at 384pt in the host. Short confirmations keep the icon, title and close control on one centered row. Details wrap below the title; their action sits below the detail to preserve reading space.
Settings
| Prop | Default | Behavior |
|---|---|---|
title | required | Main confirmation beside the icon. |
description | undefined | Optional detail below the title. |
tone | info | info, success, warning or error; selects the default status symbol and its semantic colour. |
icon | symbol for tone | Replace the leading icon; null hides it. |
duration | 1800 | Milliseconds before auto-dismiss. Zero persists; an actionable toast defaults to zero. |
onDismiss | required | Called by the trailing cross, swipe or expiry. The close target is 44pt. |
ToastHost.placement | bottom | Show at the top or bottom safe-area edge of the screen. |
ToastHost.offset | 0 | Additional clearance for a navigator or keyboard. |
The timer pauses for a native screen reader, interaction, focused controls or the background. Browsers cannot detect screen readers; web controls pause expiry while focused. Actionable messages remain persistent unless a duration is supplied. The shared queue and optional action remain available; ordinary copy confirmations use only icon, title, description and cross.
API reference
ToastProps
| Prop | Type | Default | Description |
|---|---|---|---|
preset? | | — | |
title? | | — | |
description? | | | Optional detail; null removes the preset detail. |
tone? | | | Semantic status override. |
appearance? | | | Content-width pill or notification card. |
expandable? | | | Expand long supporting text inline. |
detailPreviewLines? | | | Preview line count before expansion. |
detailFade? | | | Fade the final preview line. |
detailBlur? | | | Blur the final preview line independently of its fade. |
detailMessages? | | — | Caller wording for inline details. |
exitDirection? | | | Exit direction, independently of the safe-area placement. |
showDismiss? | | | Show a close control; pills offer an accessibility dismiss action. |
icon? | | | Leading status symbol; null hides it. |
action? | | — | Optional action; defaults to persistent until manually dismissed. |
duration? | | | Functional visibility time; 0 persists. Pauses for accessibility/interaction/background. |
onExpand? | | | Stack body expansion; separate from message actions. |
stackExpanded? | | | Current stack expansion for its named toggle. |
onInteractionChange? | | — | Notify the host when an interaction pauses automatic collapse. |
onDismiss | | — | Dismissal handler for close, swipe and expiry. |
paused? | | | Pause expiration, for example while a stack is expanded. |
announce? | | | Announce and give feedback when revealed by a stack. |
haptics? | | | Feedback when shown. |
motion? | | — | Shared overlay/press motion. |
className? | | — | Root classes. |
style? | | — | Native layout escape hatch. |
testID? | | — | Root ID. |
ToastHostProps
| Prop | Type | Default | Description |
|---|---|---|---|
presentation? | | | Single FIFO notification or a fanning stack. |
collapseAfter? | | | Collapse an expanded stack after this idle interval; zero persists. |
placement? | | | Safe-area edge. |
defaultExpanded? | | | Initial stack expansion. |
maxVisible? | | | Maximum simultaneously displayed stack cards. |
offset? | | | Add keyboard or navigator clearance when needed. |
haptics? | | | Show feedback. |
motion? | | — | Shared overlay/press motion. |
className? | | — | Root classes. |
testID? | | — | Root ID. |
Native view/input props not listed here pass through where the exported TypeScript type allows them.
Composition and behavior
- ToastProvider holds the queue; ToastHost shows it at the top or bottom safe-area edge.
- useToast() returns show, update, dismiss and clear.
- Each toast has a title, optional description, tone, action and duration.
Feedback lineup settings
| Prop | Does / default |
|---|---|
appearance | Content-width pill or notification card. @default 'card' |
showDismiss | Show a close control; pills offer an accessibility dismiss action. @default true for cards |
icon | Leading status symbol; null hides it. @default a symbol matching tone |
action | Optional action; defaults to persistent until manually dismissed. |
duration | Functional visibility time; 0 persists. Pauses for accessibility/interaction/background. @default 1800, or 0 with an action |
onDismiss | Dismissal handler for close, swipe and expiry. |
paused | Pause expiration, for example while a stack is expanded. @default false |
announce | Announce and give feedback when revealed by a stack. @default true |
haptics | Show feedback. @default true |
motion | Shared overlay/press motion. |
className | Root classes. |
style | Native layout escape hatch. |
testID | Root ID. |
presentation | Single FIFO notification or a fanning stack. @default 'stack' |
placement | Safe-area edge. @default 'bottom' |
defaultExpanded | Initial stack expansion. @default false |
maxVisible | Maximum simultaneously displayed stack cards. @default 3 |
offset | Add keyboard or navigator clearance when needed. @default 0 |
One toast queue, including stacks
Repeated show() calls form the same newest-front stack; the standard host defaults to presentation="stack". Long press a notification title to expand the stack; its named Expand/Collapse control also works with keyboard and assistive technology. Expanded stacks collapse after 3500ms of idle time (collapseAfter={0} keeps them open); touch/background/native screen-reader interaction pauses this timer. No separate count button is shown. The Toast boards include the stack; the separate Toast stack listing is retired. Existing ToastStack imports and add toast-stack remain compatible, and explicit presentation="single" retains FIFO behavior.
Pill titles use the message's semantic colour, including green Copied, and preserve their full native line height. exitDirection="up" adds an upward exit independently of host placement; its default is fade.
Inline details and swipe dismissal
Detailed cards align their leading icon/title at the top and put a circular close control at the top trailing edge. The detail wraps within the same bounded column. Set expandable for a two-line preview: the final preview line blurs and fades, with a left-aligned More details arrow. It opens the full text in place with animated height; Less details reverses it. No dialog opens.
| Prop | Default | Behavior |
|---|---|---|
expandable | false | Enable inline detail expansion. |
detailPreviewLines | 2 | Preview line count, from 1 to 8. |
detailFade | true | Fade the last preview line. |
detailBlur | true | Blur that line independently of its fade. |
detailMessages | More details / Less details | Localize expansion controls. |
ToastHost.collapseAfter | 3500 | Idle time before stack collapse; zero keeps it expanded. |
An accepted left or right swipe continues beyond the viewport before its message is removed. A cancelled swipe returns to rest. Pill surfaces retain their capsule corners throughout a collapsed stack. Each card still provides a named dismissal alternative.
The host bounds detailed cards to the measured stage width (up to 384pt) and follows their natural height, including inline expansion. Full-text measurement is independent of the clipped preview. Icon-free pills keep their title vertically centered within the minimum 44pt surface.
Behavior and gestures
- The default host stacks newest-first; presentation="single" retains FIFO. Hidden cards pause expiration; expand exposes all queued cards.
- Plain toasts disappear after 1.8 seconds; toasts with an action stay until dismissed.
- The timer pauses in the background, during interaction or control focus, and for a native screen reader. Web expiry does not rely on unreliable screen-reader detection.
- Swipe a toast sideways to dismiss it, or tap its close button.
- Each toast plays a haptic that matches its tone: success, warning, error or a light tick.
- Long press to expand; the named toggle is also available. Stacks collapse after configurable idle time. Long details can expand inline from a faded preview.
Accessibility
- The message is announced when it appears.
- Native screen-reader mode keeps toasts persistent. On the web, focused controls pause expiry; browsers cannot detect screen-reader presence.
- Action and dismiss are named buttons, so swiping is never required.
- Toasts never take focus or block the screen.
Motion
- Uses the
overlay,pressandlayoutmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Toasts fade in and out on the overlay role; swipes follow the finger.
- Reduce Motion uses a short fade.
Performance
- One host at the app root renders the queue; it doesn't depend on your router.
Notes for AI
- Add ToastProvider and one ToastHost at the root; call useToast().show({ title }).
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.