Components

Toast

Stackable toast notification system with rich colors, swipe-to-dismiss, and a Sonner-like imperative API.

iOSAndroid
Preview Toast on your device

Scan with Expo Go

Download Expo Go, then scan the QR code to preview native components.

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-toast
Required Packages(3 packages)
pnpm add react-native-gesture-handler react-native-reanimated react-native-worklets

Usage

Wrap your app with <Toaster> and use the imperative toast API or the useToaster hook.

import { Toaster, toast } from '@/components/docyrus-native/toast';

// Wrap your app
function App() {
  return (
    <Toaster position="top-center" richColors>
      <MyScreen />
    </Toaster>
  );
}

// Fire toasts from anywhere
toast.success('Changes saved');
toast.error('Upload failed');
toast.warning('Disk almost full');
toast.info('New update available');
toast.loading('Processing...');

Toaster Props

PropTypeDefaultDescription
childrenReactNode—App content to wrap
positionToastPosition'bottom-center'Default position for toasts
durationnumber4000Auto-dismiss duration in ms
gapnumber1Gap between stacked toasts
visibleToastsnumber3Maximum visible toast count
swipeDirection'up' | 'down' | 'left' | 'right''up'Swipe direction to dismiss
richColorsbooleantrueUse colored backgrounds per variant
closeButtonbooleanfalseShow close button on all toasts
swipeThresholdnumber100Swipe distance to trigger dismiss
titleMaxLinesnumber2Maximum title text lines
descMaxLinesnumber3Maximum description text lines
variantColorsPartial<Record<ToastType, Partial<ToastVariantColors>>>—Override default variant colors

ToastData Props

PropTypeDefaultDescription
idstring | number—Unique toast identifier (auto-generated)
type'success' | 'error' | 'info' | 'warning' | 'default' | 'loading''default'Toast variant type
titleReactNode—Toast title content
descriptionReactNode—Toast description content
durationnumber4000Auto-dismiss duration in ms
actionToastAction—Action button with label and onClick
iconReactNode—Custom icon element
closeButtonbooleanfalseShow close button
importantboolean—Prevent auto-dismiss
onDismiss(toast: ToastData) => void—Called when toast is dismissed
onAutoClose(toast: ToastData) => void—Called when toast auto-closes
dismissiblebooleantrueAllow swipe-to-dismiss
positionToastPosition—Override default position for this toast
classNamestring—Toast container CSS classes
titleLinesnumber—Override title max lines
descLinesnumber—Override description max lines
colorsPartial<ToastVariantColors>—Override variant colors for this toast

Type Exports

TypeDescription
ToasterPropsProps for Toaster provider component
ToastDataIndividual toast data object
ToastType'success' | 'error' | 'info' | 'warning' | 'default' | 'loading'
ToastPosition'top-center' | 'bottom-center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
ToastAction{ label: string; onClick: () => void }
ToastVariantColors{ bg: string; fg: string; icon?: string; border?: string }

On this page