Skip to main content

Overview

BreadLoaf is the main toast provider component for React Native Bread. Add it to your root layout to enable toast notifications throughout your app. On iOS, toasts render using FullWindowOverlay to appear above native modals. On Android, use ToastPortal inside modal screens for toast support.

Basic usage

import { BreadLoaf } from 'react-native-bread';

export default function RootLayout() {
  return (
    <>
      <Stack />
      <BreadLoaf />
    </>
  );
}

Configuration

import { BreadLoaf } from 'react-native-bread';

export default function RootLayout() {
  return (
    <>
      <Stack />
      <BreadLoaf
        config={{
          position: 'bottom',
          stacking: false,
          defaultDuration: 5000,
          colors: {
            success: { accent: '#22c55e', background: '#f0fdf4' },
            error: { accent: '#ef4444', background: '#fef2f2' },
          },
          toastStyle: { borderRadius: 12 },
        }}
      />
    </>
  );
}

Props

config
ToastConfig
Configuration object for customizing toast behavior and appearance. All properties are optional.

Advanced example

import { BreadLoaf, CloseIcon, GreenCheck } from 'react-native-bread';

export default function RootLayout() {
  return (
    <>
      <Stack />
      <BreadLoaf
        config={{
          position: 'top',
          offset: 20,
          stacking: true,
          maxStack: 5,
          dismissible: true,
          showCloseButton: true,
          defaultDuration: 5000,
          deduplication: true,
          colors: {
            success: {
              accent: '#10b981',
              background: '#d1fae5',
            },
            error: {
              accent: '#ef4444',
              background: '#fee2e2',
            },
            info: {
              accent: '#3b82f6',
              background: '#dbeafe',
            },
            loading: {
              accent: '#6b7280',
              background: '#f3f4f6',
            },
          },
          icons: {
            success: ({ color, size }) => (
              <GreenCheck color={color} size={size} />
            ),
            error: ({ color, size }) => (
              <CloseIcon color={color} size={size} />
            ),
          },
          toastStyle: {
            borderRadius: 16,
            paddingHorizontal: 20,
            paddingVertical: 14,
            shadowColor: '#000',
            shadowOffset: { width: 0, height: 2 },
            shadowOpacity: 0.1,
            shadowRadius: 8,
            elevation: 4,
          },
          titleStyle: {
            fontSize: 16,
            fontWeight: '700',
            letterSpacing: 0.2,
          },
          descriptionStyle: {
            fontSize: 14,
            lineHeight: 20,
            marginTop: 4,
          },
        }}
      />
    </>
  );
}

Type definitions

type ToastType = 'success' | 'error' | 'info' | 'loading';

type ToastPosition = 'top' | 'bottom';

interface ToastTypeColors {
  /** Accent color used for title text and icons */
  accent: string;
  /** Background color of the toast */
  background: string;
}

interface IconProps {
  /** The accent color from the theme for this toast type */
  color: string;
  /** Default icon size */
  size: number;
}

type IconRenderFn = (props: IconProps) => ReactNode;

type ToastConfig = {
  position?: 'top' | 'bottom';
  offset?: number;
  rtl?: boolean;
  stacking?: boolean;
  maxStack?: number;
  dismissible?: boolean;
  showCloseButton?: boolean;
  defaultDuration?: number;
  deduplication?: boolean;
  colors?: Partial<Record<ToastType, Partial<ToastTypeColors>>>;
  icons?: Partial<Record<ToastType, IconRenderFn>>;
  toastStyle?: ViewStyle;
  titleStyle?: TextStyle;
  descriptionStyle?: TextStyle;
};

Build docs developers (and LLMs) love