rslabdocs

Toast

A dismissible toast that slides down from the top, auto-dismisses, and follows your finger if you swipe it away early.

ReanimatedGesture HandlerHapticsSource

Prerequisites

Toast needs a pan gesture for swipe-to-dismiss, plus icons, haptics, and Reanimated.


npx expo install @hugeicons/core-free-icons @hugeicons/react-native expo-haptics react-native-gesture-handler react-native-reanimated

Install


npx @rslab/cli add toast

Usage

Mount one Toast near the root of your screen and drive it from a small piece of state, there's no built-in queue, so stacking multiple toasts is left to whatever you put around it.

import { Toast, ToastVariant } from '@/components/ui/Toast';

const [toast, setToast] = useState<{
  message: string;
  variant: ToastVariant;
} | null>(null);

<Toast
  visible={!!toast}

  message={toast?.message ?? ''}

  variant={toast?.variant}

  onDismiss={() => setToast(null)}
/>;
setToast({ message: 'Changes saved', variant: 'success' });

setToast({ message: 'Could not connect', variant: 'error' });

Props

PropTypeDefault
visible
boolean
-

Controls the entrance and exit animation.

message
string
-

Toast text, wraps up to 2 lines.

onDismiss
() => void
-

Called on auto-dismiss, swipe-to-dismiss, or timeout.

variant?
'neutral''success''error''info'
'neutral'

Adds a leading icon for every variant except neutral, and picks the entrance haptic.

duration?
number
2800

Auto-dismiss delay in ms. Set 0 to disable auto-dismiss.

haptic?
boolean
true

Mute the entrance notification haptic.

See exactly how this works with an RSLAB subscription.

Get Pro

On this page