Toast

Toast is a component that can display alerts, notifications, or messages on top of an overlay layer. It is commonly used to inform users of important information or actions.
Installation
API Reference
This is an illustration of Toast component.
action
variant
function Example() {
const toast = useToast()
return (
<Button
onPress={() => {
toast.show({
placement: "top",
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast nativeID={toastId} action="attention" variant="solid">
<VStack space="xs">
<ToastTitle>New Message</ToastTitle>
<ToastDescription>
Hey, just wanted to touch base and see how you're doing.
Let's catch up soon!
</ToastDescription>
</VStack>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Installation

Run the following command:

npx gluestack-ui add toast

API Reference

To use this component in your project, include the following import statement in your file.
import { useToast, Toast } from "@/components/ui/toast"
export default () => (
<Toast>
<ToastTitle />
<ToastDescription />
</Toast>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Toast

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
duration
number or null
5000
The delay before the toast hides (in milliseconds). If set to null, toast will never dismiss.
onCloseComplete
()=>{}
-
Callback function to run side effects after the toast has closed.
placement
'top'| 'top right' | 'top left' | 'bottom' | 'bottom left' | 'bottom right'
bottom
Position of toast on the web page.
render?: (props: any)
ReactNode
-
Renders a toast component
avoidKeyboard
bool
false
If true and the keyboard is opened, the Toast will move up equivalent to the keyboard height.
containerStyle
ViewStyle
-
Container style object for the toast.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_icon
Prop to style Icon Component
_title
Prop to style AlertTitle Component
_description
Prop to style AlertDescription Component

ToastTitle

Contains all Text related layout style props and actions. It inherits all the properties of React Native's Text component.

ToastDescription

Contains all Text related layout style props and actions. It inherits all the properties of React Native's Text component.

Accessibility

We have outlined the various features that ensure the Toast component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the WAI-ARIA design pattern.

Keyboard

  • Tab + Enter: Triggers the toast's action.

Screen Reader

  • VoiceOver: When the toast is focused, the screen reader will announce the toast's title.

Props

Toast component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

Toast

Name
Value
Default
action
error | warning | success | info | attention
attention
variant
solid | outline | accent
solid

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Toast with actions

A versatile Toast component with customizable actions, enabling users to take various actions directly from the notification popup for enhanced usability and convenience.
function Example() {
const toast = useToast()
const toastActions = [
{
actionType: "info",
title: "Info",
description:
"Your order has been received and is being processed. You will receive a confirmation email shortly.",
},
{
actionType: "success",
title: "Success!",
description: "Your changes have been saved successfully.",
},
{
actionType: "warning",
title: "Warning!",
description:
"Your account subscription will expire in 5 days. Please renew your subscription to avoid interruption of service.",
},
{
actionType: "error",
title: "Error!",
description:
"There was an error processing your request. Please try again later.",
},
{
actionType: "attention",
title: "Attention!",
description:
"Please review and accept our updated terms and conditions before continuing to use the application.",
},
]
return (
<Center h="$80">
<VStack space="md">
{toastActions.map((action, index) => {
return (
<Button
key={index}
onPress={() => {
toast.show({
placement: "top",
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast nativeID={toastId} action={action.actionType}>
<VStack space="xs">
<ToastTitle>{action.title}</ToastTitle>
<ToastDescription>
{action.description}
</ToastDescription>
</VStack>
</Toast>
)
},
})
}}
>
<ButtonText>{action.actionType}</ButtonText>
</Button>
)
})}
</VStack>
</Center>
)
}

Toast with variants

A versatile Toast component with multiple variants, offering different styles and visual cues to effectively convey various types of notifications and feedback to users.
variant
function Example() {
const toast = useToast()
return (
<Button
onPress={() => {
toast.show({
placement