Looking for documentation on gluestack-ui with NativeWind (alpha) version? Refer to this link.
This is an illustration of a Themed Toast component with default configuration.
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" flex={1}>
<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>
)
}

API Reference

Import

To use this component in your project, include the following import statement in your file.
import { useToast, Toast } from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a Toast component's various parts.
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.show

The following props can be passed while calling toast.show.
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.

Themed

The themed version of the component is a pre-styled version of the component, which allows you to quickly integrate the component into your project. The component's design and functionality are fully defined, allowing you to focus on the more important aspects of your project. To know more about Themed Library please visit this link.

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
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

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" flex={1}>
<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: "top",
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast nativeID={toastId} variant="solid" action="success">
<VStack space="xs" flex={1}>
<ToastTitle>Attention!</ToastTitle>
<ToastDescription>
Please review and accept our updated terms and conditions
before continuing to use the application.
</ToastDescription>
</VStack>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Toast with placement

A Toast component with different placement options allows for the flexible positioning of toast notifications, enabling them to appear in various locations within a user interface, enhancing user visibility and providing a customizable approach to displaying temporary messages or alerts.
placement
function Example() {
const toast = useToast()
const placements = {
bottom: "Looks like you found the hiding spot at the bottom of the page!",
top: "The top spot is your favorite hiding spot! Keep hunting for success.",
"top right":
"You're hiding in plain sight at the top right corner! You are good at this game.",
"top left":
"You're a master of disguise hiding in the top left corner! Keep up the sneakiness.",
"bottom left":
"You're not the best at hiding, but we found you in the bottom left corner.",
"bottom right": "Found you! Don't worry, we wont tell anyone.",
}
const placement = "bottom"
return (
<Button
onPress={() => {
toast.show({
placement: placement,
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast nativeID={toastId}>
<ToastDescription>{placements[placement]}</ToastDescription>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Dismissable Toast

A dismissable Toast component offers users the ability to dismiss or close the toast notification, providing control and convenience in managing temporary messages or alerts within a user interface.
function Example() {
const toast = useToast()
return (
<Button
onPress={() => {
toast.show({
placement: "top",
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast bg="$success700" nativeID={toastId}>
<Icon as={CheckIcon} color="$white" mt="$1" mr="$3" />
<VStack space="xs" flex={1}>
<ToastTitle color="$textLight50">
Download Complete
</ToastTitle>
<ToastDescription color="$textLight50">
Your file 'wadewarren.docx' has been downloaded
successfully. You can find it in your Downloads folder.
</ToastDescription>
</VStack>
<Pressable mt="$1" onPress={() => toast.close(id)}>
<Icon as={CloseIcon} color="$coolGray50" />
</Pressable>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Toast custom duration

A Toast component with custom duration allows for specifying the length of time the toast notification remains visible, offering flexibility in controlling the duration of temporary messages or alerts within a user interface.
duration
function Example() {
const toast = useToast()
const duration = "5000"
return (
<Button
onPress={() => {
toast.show({
placement: "top",
duration: duration,
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast bg="$secondary700" nativeID={toastId} p="$3">
<Icon as={MessageCircle} color="$white" mt="$1" mr="$3" />
<VStack space="xs" flex={1}>
<ToastTitle color="$textLight50">New Message</ToastTitle>
<ToastDescription color="$textLight50">
Hey, just wanted to touch base and see how you're doing.
Let's catch up soon!
</ToastDescription>
</VStack>
<Pressable mt="$1" onPress={() => toast.close(id)}>
<Icon as={CloseIcon} color="$coolGray50" />
</Pressable>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Preserve Toast

A Toast component with preserve toast functionality retains the notification on the screen until explicitly dismissed, ensuring important messages or alerts remain visible and accessible to the user, even during subsequent interactions within the user interface.
function Example() {
const toast = useToast()
return (
<Button
onPress={() => {
toast.show({
placement: "top",
duration: null,
render: ({ id }) => {
const toastId = "toast-" + id
return (
<Toast bg="$error700" nativeID={toastId} p="$3">
<Icon as={AlertTriangleIcon} color="$white" mt="$1" mr="$3" />
<VStack space="xs" flex={1}>
<ToastTitle color="$textLight50">
Account Security Alert
</ToastTitle>
<ToastDescription color="$textLight50">
Your account password was recently changed. If you did not
authorize this change, please contact our support team
immediately.
</ToastDescription>
</VStack>
<Pressable mt="$1" onPress={() => toast.close(id)}>
<Icon as={CloseIcon} color="$coolGray50" />
</Pressable>
</Toast>
)
},
})
}}
>
<ButtonText>Press Me</ButtonText>
</Button>
)
}

Unstyled

All the components in gluestack-ui are unstyled by default. To customize your UI using the extendedTheme, please refer to this link. The import names of components serve as keys to customize each component.

Spec Doc

Explore the comprehensive details of the Toast in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.