import { Button, useToast } from "@vortexlabs/vortex-native";
export const SaveNotice = () => {
const { show, hide } = useToast();
return (
<Button onPress={() => {
const id = show({
tone: "success",
layout: "inline",
title: "Changes saved",
position: "bottom",
closable: true,
closeAriaLabel: "Dismiss save notification",
actionsSlot: <Button onPress={() => hide(id)}>Done</Button>,
});
}}>
Show save notification
</Button>
);
};Features
- Shows and dismisses notifications with
useToast. - Supports seven tones, optional icons, and inline or stacked actions.
- Queues notifications separately at the top and bottom of the screen.
- Supports swiping toward the screen edge to dismiss a visible toast.
Tones and Layout
Use tone to match the message. An icon appears before the text and takes precedence over startSlot. Set layout="stacked" to move actions below the message.
import { CircleCheck, TriangleExclamation } from "@vortexlabs/vortex-icons";
import { Button, Stack, useToast } from "@vortexlabs/vortex-native";
const toastVariants = [
{
label: "Inline success",
title: "Changes saved",
tone: "success",
layout: "inline",
icon: CircleCheck,
},
{
label: "Stacked warning",
title: "Storage is nearly full",
tone: "warning",
layout: "stacked",
icon: TriangleExclamation,
},
] as const;
export const ToastTonesAndLayouts = () => {
const { show, hide } = useToast();
return (
<Stack gap={2}>
{toastVariants.map(({ label, ...toast }) => (
<Button
key={label}
variant="secondary"
onPress={() => {
const id = show({
...toast,
timeout: 0,
actionsSlot: <Button onPress={() => hide(id)}>OK</Button>,
});
}}
>
{label}
</Button>
))}
</Stack>
);
};Duration
timeout defaults to "brief" (4 seconds). Use "extended" for 8 seconds, a number of milliseconds, or 0 to leave the message open until dismissed. Pressing and holding a visible toast pauses its timer.
import { Button, Stack, useToast } from "@vortexlabs/vortex-native";
export const ToastDurations = () => {
const { show } = useToast();
return (
<Stack gap={2}>
<Button variant="secondary" onPress={() => show({ title: "Link copied" })}>
Show for 4 seconds
</Button>
<Button variant="secondary" onPress={() => show({ title: "Draft saved", timeout: "extended" })}>
Show for 8 seconds
</Button>
</Stack>
);
};Actions
Pass buttons in actionsSlot. Use the ID returned by show to dismiss the notification after its action runs.
import { Button, useToast } from "@vortexlabs/vortex-native";
import React from "react";
export const ToastUndo = () => {
const [archived, setArchived] = React.useState(false);
const { show, hide } = useToast();
const archive = () => {
setArchived(true);
const id = show({
title: "Message archived",
layout: "stacked",
timeout: 0,
closable: true,
closeAriaLabel: "Dismiss archive notification",
actionsSlot: <Button onPress={() => {
setArchived(false);
hide(id);
}}>Undo</Button>,
});
};
return (
<Button disabled={archived} onPress={archive}>
{archived ? "Message archived" : "Archive message"}
</Button>
);
};Position and Stacks
Set position to "top" or "bottom". Each edge has its own queue, with the newest toast in front. Tap the front card to expand the stack and inspect earlier messages.
import { Button, Stack, useToast } from "@vortexlabs/vortex-native";
export const ToastStacks = () => {
const { show } = useToast();
return (
<Stack gap={2}>
<Button variant="secondary" onPress={() => show({
position: "top",
title: "Export ready",
timeout: 0,
closable: true,
closeAriaLabel: "Dismiss export notification",
})}>
Notify at the top
</Button>
<Button variant="secondary" onPress={() => show({
position: "bottom",
title: "Changes saved",
timeout: 0,
closable: true,
closeAriaLabel: "Dismiss save notification",
})}>
Notify at the bottom
</Button>
</Stack>
);
};Separate Queues
VortexProvider provides app-level queues. For a separate queue inside a screen, wrap it in ToastProvider. The hook uses the nearest provider, and notifications align to its containing view.
import { Stack, ToastProvider } from "@vortexlabs/vortex-native";
<Stack flex={1}>
<ToastProvider options={{ bottom: { width: 320, expanded: true } }}>
<Inbox />
</ToastProvider>
</Stack>Accessibility
closeAriaLabel when closable is true. Screen reader users can also dismiss a toast with its Dismiss action, named by dismissAriaLabel.