Mobile › Overlays

Toast

A short message after an action, with an optional Undo. Wrap the app in ToastProvider and call useToast().

Installation

npx expo install plankui-mobile react-native-safe-area-context expo-haptics

Usage

import { ToastProvider, useToast, Button } from "plankui-mobile";

// Once, near the root:
<ToastProvider bottomOffset={80}>{/* app */}</ToastProvider>

// Anywhere inside:
const toast = useToast();
toast("Saved");
toast({ message: "Message deleted", action: { label: "Undo", onPress: restore } });
toast({ message: "Couldn't upload", tone: "error" });

iOS and Android

iOS: A pill that drops from the top; screen readers announce it.

Android: A Material snackbar at the bottom, above the tab bar.

API reference

PropTypeDefaultDescription
messagestringWhat happened.
action{ label: string; onPress: () => void }–One action, such as Undo.
tone"default" | "success" | "error""default"Adds a coloured dot and a matching haptic.
durationnumber4000Milliseconds; 6000 when there is an action.

ToastProvider

PropTypeDefaultDescription
bottomOffsetnumber0Space kept clear at the bottom on Android, such as the tab bar height.