ToastUpdated

Displays temporary notification messages that appear at the top or bottom of the screen.

Import

import { Toast, useToast } from 'heroui-native';

Anatomy

<Toast>
  <Toast.Title>...</Toast.Title>
  <Toast.Description>...</Toast.Description>
  <Toast.Action>...</Toast.Action>
  <Toast.Close />
</Toast>
  • Toast: Main container that displays notification messages. Handles positioning, animations, and swipe gestures.
  • Toast.Title: Title text of the toast notification. Inherits variant styling from parent Toast context.
  • Toast.Description: Descriptive text content displayed below the title.
  • Toast.Action: Action button within the toast. Button variant is automatically determined based on toast variant but can be overridden.
  • Toast.Close: Close button for dismissing the toast. Renders as an icon-only button that calls hide when pressed.

Usage

Usage Pattern 1: Simple String

Show a toast with a simple string message.

const { toast } = useToast();

toast.show('This is a toast message');

Usage Pattern 2: Config Object

Show a toast with label, description, variant, and action button using a config object.

const { toast } = useToast();

toast.show({
  variant: 'success',
  label: 'You have upgraded your plan',
  description: 'You can continue using HeroUI Chat',
  icon: <Icon name="check" />,
  actionLabel: 'Close',
  onActionPress: ({ hide }) => hide(),
});

Usage Pattern 3: Custom Component

Show a toast with a fully custom component for complete control over styling and layout.

const { toast } = useToast();

toast.show({
  component: (props) => (
    <Toast variant="accent" placement="top" {...props}>
      <Toast.Title>Custom Toast</Toast.Title>
      <Toast.Description>This is a custom toast component</Toast.Description>
      <Toast.Close />
    </Toast>
  ),
});

Note: Toast items are memoized for performance. If you need to pass external state (like loading state) to a custom toast component, it will not update automatically. Use shared state techniques instead, such as React Context, state management libraries, or refs to ensure state updates propagate to the toast component.

Disabling All Animations

Disable all animations including children by using "disable-all". This cascades down to all child components (like Button in Toast.Action).

const { toast } = useToast();

toast.show({
  variant: 'success',
  label: 'Operation completed',
  description: 'All animations are disabled',
  animation: 'disable-all',
});

Or with a custom component:

const { toast } = useToast();

toast.show({
  component: (props) => (
    <Toast variant="accent" animation="disable-all" {...props}>
      <Toast.Title>No animations</Toast.Title>
      <Toast.Description>
        This toast has all animations disabled
      </Toast.Description>
      <Toast.Action>Action</Toast.Action>
    </Toast>
  ),
});

Example

import { Button, Toast, useToast, useThemeColor } from 'heroui-native';
import { View } from 'react-native';

export default function ToastExample() {
  const { toast } = useToast();
  const themeColorForeground = useThemeColor('foreground');

  return (
    <View className="gap-4 p-4">
      <Button
        onPress={() =>
          toast.show({
            variant: 'success',
            label: 'You have upgraded your plan',
            description: 'You can continue using HeroUI Chat',
            actionLabel: 'Close',
            onActionPress: ({ hide }) => hide(),
          })
        }
      >
        Show Success Toast
      </Button>

      <Button
        onPress={() =>
          toast.show({
            component: (props) => (
              <Toast variant="accent" {...props}>
                <Toast.Title>Custom Toast</Toast.Title>
                <Toast.Description>
                  This uses a custom component
                </Toast.Description>
                <Toast.Action onPress={() => props.hide()}>Undo</Toast.Action>
                <Toast.Close className="absolute top-0 right-0" />
              </Toast>
            ),
          })
        }
      >
        Show Custom Toast
      </Button>
    </View>
  );
}

You can find more examples in the GitHub repository.

Global Configuration

Configure toast behavior globally using HeroUINativeProvider config prop. Global configs serve as defaults for all toasts unless overridden locally.

Note: For complete provider configuration options, see the Provider documentation.

Insets

Insets control the distance of toast sides from screen edges. Insets are added to safe area insets. To set all toasts to have a side distance of 20px from screen edges, configure insets:

<HeroUINativeProvider
  config={{
    toast: {
      insets: {
        top: 20,
        bottom: 20,
        left: 20,
        right: 20,
      },
    },
  }}
>
  {children}
</HeroUINativeProvider>

Content Wrapper with KeyboardAvoidingView

Wrap toast content with KeyboardAvoidingView to ensure toasts adjust when the keyboard appears:

import {
  KeyboardAvoidingView,
  KeyboardProvider,
} from 'react-native-keyboard-controller';
import { HeroUINativeProvider } from 'heroui-native';
import { useCallback } from 'react';

function AppContent() {
  const contentWrapper = useCallback(
    (children: React.ReactNode) => (
      <KeyboardAvoidingView
        pointerEvents="box-none"
        behavior="padding"
        keyboardVerticalOffset={12}
        className="flex-1"
      >
        {children}
      </KeyboardAvoidingView>
    ),
    []
  );

  return (
    <KeyboardProvider>
      <HeroUINativeProvider
        config={{
          toast: {
            contentWrapper,
          },
        }}
      >
        {children}
      </HeroUINativeProvider>
    </KeyboardProvider>
  );
}

Default Props

Set global defaults for variant, placement, animation, and swipe behavior:

<HeroUINativeProvider
  config={{
    toast: {
      defaultProps: {
        variant: 'accent',
        placement: 'bottom',
        isSwipeable: false,
      },
    },
  }}
>
  {children}
</HeroUINativeProvider>

Limiting the Number of Toasts

By default every toast is kept until it is dismissed: maxVisibleToasts only controls how many are drawn, and the rest wait behind the stack and come back when the toasts in front of them are dismissed. Set maxToasts to drop the oldest toasts instead. With maxToasts: 1, every new toast replaces the previous one:

<HeroUINativeProvider
  config={{
    toast: {
      maxToasts: 1,
    },
  }}
>
  {children}
</HeroUINativeProvider>

A toast dropped by the limit is dismissed as if toast.hide(id) had been called: it plays its exit animation, its auto-dismiss timer is cleared and its onHide callback runs.

API Reference

Toast

proptypedefaultdescription
variant'default' | 'accent' | 'success' | 'warning' | 'danger''default'Visual variant of the toast
placement'top' | 'bottom''top'Placement of the toast on screen
isSwipeablebooleantrueWhether the toast can be swiped to dismiss and dragged with rubber effect
animationToastRootAnimation-Animation configuration
isAnimatedStyleActivebooleantrueWhether animated styles (react-native-reanimated) are active
classNamestring-Additional CSS class for the toast container
...ViewPropsViewProps-All standard React Native View props are supported

ToastRootAnimation

Animation configuration for Toast component. Can be:

  • false or "disabled": Disable only root animations
  • "disable-all": Disable all animations including children
  • true or undefined: Use default animations
  • object: Custom animation configuration
proptypedefaultdescription
state'disabled' | 'disable-all' | boolean-Disable animations while customizing properties
opacity.value[number, number][1, 0]Opacity interpolation values for fade effect as toasts move beyond visible stack
opacity.timingConfigWithTimingConfig{ duration: 300 }Animation timing configuration for opacity transitions
translateY.value[number, number][0, 10]Translate Y interpolation values for peek effect of stacked toasts
translateY.timingConfigWithTimingConfig{ duration: 300 }Animation timing configuration for translateY transitions
scale.value[number, number][1, 0.97]Scale interpolation values for depth effect of stacked toasts
scale.timingConfigWithTimingConfig{ duration: 300 }Animation timing configuration for scale transitions
entering.topEntryOrExitLayoutTypeFadeInUp
.springify()
.withInitialValues({ opacity: 1, transform: [{ translateY: -100 }] })
.mass(3)
Custom entering animation for top placement
entering.bottomEntryOrExitLayoutTypeFadeInDown
.springify()
.withInitialValues({ opacity: 1, transform: [{ translateY: 100 }] })
.mass(3)
Custom entering animation for bottom placement
exiting.topEntryOrExitLayoutTypeKeyframe animation with
translateY: -100, scale: 0.97, opacity: 0.5
Custom exiting animation for top placement
exiting.bottomEntryOrExitLayoutTypeKeyframe animation with
translateY: 100, scale: 0.97, opacity: 0.5
Custom exiting animation for bottom placement

Toast.Title

proptypedefaultdescription
childrenReact.ReactNode-Content to be rendered as title
classNamestring-Additional CSS classes
...TextPropsTextProps-All standard React Native Text props are supported

Toast.Description

proptypedefaultdescription
childrenReact.ReactNode-Content to be rendered as description
classNamestring-Additional CSS classes
...TextPropsTextProps-All standard React Native Text props are supported

Toast.Action

Toast.Action extends all props from Button component. Button variant is automatically determined based on toast variant but can be overridden.

proptypedefaultdescription
childrenReact.ReactNode-Content to be rendered as action button label
variantButtonVariant-Button variant. If not provided, automatically determined from toast variant
size'sm' | 'md' | 'lg''sm'Size of the action button
classNamestring-Additional CSS classes

For inherited props including onPress, isDisabled, and all Button props, see Button API Reference.

Toast.Close

Toast.Close extends all props from Button component.

proptypedefaultdescription
childrenReact.ReactNode-Custom close icon. Defaults to CloseIcon
iconProps{ size?: number; color?: string }-Props for the default close icon
size'sm' | 'md' | 'lg''sm'Size of the close button
classNamestring-Additional CSS classes
onPress(event: any) => void-Custom press handler. Defaults to hiding toast

For inherited props including isDisabled and all Button props, see Button API Reference.

ToastProviderProps

Props for configuring toast behavior globally via HeroUINativeProvider config prop.

proptypedefaultdescription
defaultPropsToastGlobalConfig-Global toast configuration used as defaults for all toasts
disableFullWindowOverlaybooleanfalseWhen true on iOS, uses View instead of FullWindowOverlay. Enables element inspector; toasts won't appear above native modals
unstable_accessibilityContainerViewIsModalbooleanfalseControls whether VoiceOver treats the overlay window as a modal container. When true, VoiceOver is restricted to elements inside the overlay. iOS only. Unstable: may change with react-native-screens updates
insetsToastInsets-Insets for spacing from screen edges (added to safe area insets)
maxVisibleToastsnumber3Maximum number of visible toasts before opacity starts fading
maxToastsnumber-Maximum number of toasts kept at once. A new toast past the limit dismisses the oldest ones, so 1 makes each toast replace the previous one
contentWrapper(children: React.ReactNode) => React.ReactElement-Custom wrapper function to wrap toast content
childrenReact.ReactNode-Children to render

ToastGlobalConfig

Global toast configuration used as defaults for all toasts unless overridden locally.

proptypedescription
variant'default' | 'accent' | 'success' | 'warning' | 'danger'Visual variant of the toast
placement'top' | 'bottom'Placement of the toast on screen
isSwipeablebooleanWhether the toast can be swiped to dismiss and dragged with rubber effect
animationToastRootAnimationAnimation configuration for toast

ToastInsets

Insets for spacing from screen edges. Values are added to safe area insets.

proptypedefaultdescription
topnumber-Inset from the top edge in pixels (added to safe area inset). Platform-specific: iOS = 0, Android = 12
bottomnumber-Inset from the bottom edge in pixels (added to safe area inset). Platform-specific: iOS = 6, Android = 12
leftnumber-Inset from the left edge in pixels (added to safe area inset). Default: 12
rightnumber-Inset from the right edge in pixels (added to safe area inset). Default: 12

Hooks

useToast

Hook to access toast functionality. Must be used within a ToastProvider (provided by HeroUINativeProvider).

return valuetypedescription
toastToastManagerToast manager with show and hide methods
isToastVisiblebooleanWhether any toast is currently visible

ToastManager

methodtypedescription
show(options: string | ToastShowOptions) => stringShow a toast. Returns the ID of the shown toast. Supports three usage patterns: simple string, config object, or custom component
hide(ids?: string | string[] | 'all') => voidHide one or more toasts. No argument hides the last toast, 'all' hides all toasts, single ID or array of IDs hides specific toast(s)

ToastShowOptions

Options for showing a toast. Can be either a config object with default styling or a custom component.

When using config object (without component):

proptypedefaultdescription
variant'default' | 'accent' | 'success' | 'warning' | 'danger'-Visual variant of the toast
placement'top' | 'bottom'-Placement of the toast on screen
isSwipeableboolean-Whether the toast can be swiped to dismiss
animationToastRootAnimation | false | "disabled" | "disable-all"-Animation configuration for toast
durationnumber | 'persistent'4000Duration in milliseconds before auto-hide. 0 auto-hides on the next tick; only 'persistent' keeps the toast on screen indefinitely
idstring-Optional ID for the toast. If not provided, one will be generated
labelstring-Label text for the toast
descriptionstring-Description text for the toast
actionLabelstring-Action button label text
onActionPress(helpers: { show: (options: string | ToastShowOptions) => string; hide: (ids?: string | string[] | 'all') => void }) => void-Callback function called when the action button is pressed
iconReact.ReactNode-Icon element to display in the toast
onShow() => void-Callback function called when the toast is shown
onHide() => void-Callback function called when the toast is hidden

When using custom component:

proptypedefaultdescription
idstring-Optional ID for the toast. If not provided, one will be generated
component(props: ToastComponentProps) => React.ReactElement-A function that receives toast props and returns a React element
durationnumber | 'persistent'4000Duration in milliseconds before auto-hide. 0 auto-hides on the next tick; only 'persistent' keeps the toast on screen indefinitely
onShow() => void-Callback function called when the toast is shown
onHide() => void-Callback function called when the toast is hidden

Special Notes

Showing Many Toasts

Toasts that are pushed behind the visible stack (beyond maxVisibleToasts) are fully transparent, so only the visible stack and the one toast fading out behind it are mounted. The others stay queued with their auto-dismiss timers running and mount again, without an entering animation, once toasts in front of them are dismissed. Calling toast.show() many times in a row therefore keeps the rendering cost bounded by maxVisibleToasts.

To drop older toasts instead of queueing them, set maxToasts. With maxToasts={1} every new toast replaces the previous one: the old toast plays its exit animation and its onHide runs, and it does not come back when the new toast is dismissed.

Stack positions and heights live in Reanimated shared values and are animated on the UI thread: showing or dismissing a toast mounts or unmounts only that toast, and the toasts already on screen do not re-render. Toasts built from a string or config object never re-render when their position changes; a custom component toast re-renders when its index changes, since it receives the live index in its props. Only the front toast lays out at its natural height; the toasts behind it spring to that height and their content is covered. While the front toast is dragged, the toast behind it shows its content, so it is readable as the front one is swiped away.

The toast object returned by useToast() is referentially stable, so showing or hiding a toast does not re-render the components that call the hook. A component re-renders when the first toast appears or the last one leaves only if it reads isToastVisible.

While a toast is being dragged, its auto-dismiss timer is paused and resumes with the time it had left when the toast is released. The toast overlay stays mounted for a moment after the last toast is hidden, so its exit animation can finish.

Element Inspector (iOS)

Toast uses FullWindowOverlay on iOS. To enable the React Native element inspector during development, set disableFullWindowOverlay={true} on ToastProvider (via config.toast when using HeroUINativeProvider). Tradeoff: toasts will not appear above native modals when disabled.

On this page

Build faster with HeroUI ProComponents, templates & AI toolingExplore Pro