SwipeUI

Toast

Compact status notifications with an icon, title, detail and close control at either safe-area edge.

npx @swipeui/cli add toast
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.tsx and 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 install so versions match your SDK.

Usage

app/_layout.tsx
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

PropDefaultBehavior
titlerequiredMain confirmation beside the icon.
descriptionundefinedOptional detail below the title.
toneinfoinfo, success, warning or error; selects the default status symbol and its semantic colour.
iconsymbol for toneReplace the leading icon; null hides it.
duration1800Milliseconds before auto-dismiss. Zero persists; an actionable toast defaults to zero.
onDismissrequiredCalled by the trailing cross, swipe or expiry. The close target is 44pt.
ToastHost.placementbottomShow at the top or bottom safe-area edge of the screen.
ToastHost.offset0Additional 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

PropTypeDefaultDescription
preset?union—
title?string—
description?string | nullpreset detail

Optional detail; null removes the preset detail.

tone?FeedbackTonepreset tone or info

Semantic status override.

appearance?"card" | "pill"'card'

Content-width pill or notification card.

expandable?booleanfalse

Expand long supporting text inline.

detailPreviewLines?number2

Preview line count before expansion.

detailFade?booleantrue

Fade the final preview line.

detailBlur?booleantrue

Blur the final preview line independently of its fade.

detailMessages?{ more: string; less: string; }—

Caller wording for inline details.

exitDirection?"fade" | "up"'fade'

Exit direction, independently of the safe-area placement.

showDismiss?booleantrue for cards

Show a close control; pills offer an accessibility dismiss action.

icon?ReactNodea symbol matching tone

Leading status symbol; null hides it.

action?{ label: string; onPress: () => void; }—

Optional action; defaults to persistent until manually dismissed.

duration?number1800, or 0 with an action

Functional visibility time; 0 persists. Pauses for accessibility/interaction/background.

onExpand?((expanded?: boolean) => void)undefined

Stack body expansion; separate from message actions.

stackExpanded?booleanfalse

Current stack expansion for its named toggle.

onInteractionChange?((active: boolean) => void)—

Notify the host when an interaction pauses automatic collapse.

onDismiss() => void—

Dismissal handler for close, swipe and expiry.

paused?booleanfalse

Pause expiration, for example while a stack is expanded.

announce?booleantrue

Announce and give feedback when revealed by a stack.

haptics?booleantrue

Feedback when shown.

motion?MotionOverride—

Shared overlay/press motion.

className?string—

Root classes.

style?StyleProp<ViewStyle>—

Native layout escape hatch.

testID?string—

Root ID.

ToastHostProps

PropTypeDefaultDescription
presentation?"single" | "stack"'stack'

Single FIFO notification or a fanning stack.

collapseAfter?number3500

Collapse an expanded stack after this idle interval; zero persists.

placement?"bottom" | "top"'bottom'

Safe-area edge.

defaultExpanded?booleanfalse

Initial stack expansion.

maxVisible?number3

Maximum simultaneously displayed stack cards.

offset?number0

Add keyboard or navigator clearance when needed.

haptics?booleantrue

Show feedback.

motion?MotionOverride—

Shared overlay/press motion.

className?string—

Root classes.

testID?string—

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

PropDoes / default
appearanceContent-width pill or notification card. @default 'card'
showDismissShow a close control; pills offer an accessibility dismiss action. @default true for cards
iconLeading status symbol; null hides it. @default a symbol matching tone
actionOptional action; defaults to persistent until manually dismissed.
durationFunctional visibility time; 0 persists. Pauses for accessibility/interaction/background. @default 1800, or 0 with an action
onDismissDismissal handler for close, swipe and expiry.
pausedPause expiration, for example while a stack is expanded. @default false
announceAnnounce and give feedback when revealed by a stack. @default true
hapticsShow feedback. @default true
motionShared overlay/press motion.
classNameRoot classes.
styleNative layout escape hatch.
testIDRoot ID.
presentationSingle FIFO notification or a fanning stack. @default 'stack'
placementSafe-area edge. @default 'bottom'
defaultExpandedInitial stack expansion. @default false
maxVisibleMaximum simultaneously displayed stack cards. @default 3
offsetAdd 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.

PropDefaultBehavior
expandablefalseEnable inline detail expansion.
detailPreviewLines2Preview line count, from 1 to 8.
detailFadetrueFade the last preview line.
detailBlurtrueBlur that line independently of its fade.
detailMessagesMore details / Less detailsLocalize expansion controls.
ToastHost.collapseAfter3500Idle 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, press and layout motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items