Toast
A dismissible toast that slides down from the top, auto-dismisses, and follows your finger if you swipe it away early.
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
visibleboolean-Controls the entrance and exit animation.
messagestring-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?number2800Auto-dismiss delay in ms. Set 0 to disable auto-dismiss.
haptic?booleantrueMute the entrance notification haptic.
See exactly how this works with an RSLAB subscription.
Get Pro