function Example() {const toast = useToast()return (<ButtononPress={() => {toast.show({placement: "top",render: ({ id }) => {const toastId = "toast-" + idreturn (<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>)}
import { useToast, Toast } from "@gluestack-ui/themed"
export default () => (<Toast><ToastTitle /><ToastDescription /></Toast>)
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. |
Sx Prop | Description |
---|---|
_icon | Prop to style Icon Component |
_title | Prop to style AlertTitle Component |
_description | Prop to style AlertDescription Component |
Name | Value | Default |
---|---|---|
action | error | warning | success | info | attention | attention |
variant | solid | outline | accent | solid |
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 (<Buttonkey={index}onPress={() => {toast.show({placement: "top",render: ({ id }) => {const toastId = "toast-" + idreturn (<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>)}
function Example() {const toast = useToast()return (<ButtononPress={() => {toast.show({placement: "top",render: ({ id }) => {const toastId = "toast-" + idreturn (<Toast nativeID={toastId} variant="solid" action="success"><VStack space="xs" flex={1}><ToastTitle>Attention!</ToastTitle><ToastDescription>Please review and accept our updated terms and conditionsbefore continuing to use the application.</ToastDescription></VStack></Toast>)},})}}><ButtonText>Press Me</ButtonText></Button>)}
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 (<ButtononPress={() => {toast.show({placement: placement,render: ({ id }) => {const toastId = "toast-" + idreturn (<Toast nativeID={toastId}><ToastDescription>{placements[placement]}</ToastDescription></Toast>)},})}}><ButtonText>Press Me</ButtonText></Button>)}
function Example() {const toast = useToast()return (<ButtononPress={() => {toast.show({placement: "top",render: ({ id }) => {const toastId = "toast-" + idreturn (<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 downloadedsuccessfully. 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>)}
function Example() {const toast = useToast()const duration = "5000"return (<ButtononPress={() => {toast.show({placement: "top",duration: duration,render: ({ id }) => {const toastId = "toast-" + idreturn (<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>)}
function Example() {const toast = useToast()return (<ButtononPress={() => {toast.show({placement: "top",duration: null,render: ({ id }) => {const toastId = "toast-" + idreturn (<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 notauthorize this change, please contact our support teamimmediately.</ToastDescription></VStack><Pressable mt="$1" onPress={() => toast.close(id)}><Icon as={CloseIcon} color="$coolGray50" /></Pressable></Toast>)},})}}><ButtonText>Press Me</ButtonText></Button>)}