reactnatively
Toast
An imperative toast notification system. Call toast.show() or the typed shorthands from anywhere in your app. Add <ToastProvider /> once at the root.
Setup
App.tsx
import { ToastProvider } from 'reactnatively';
import { RootNavigator } from './navigation';
export default function App() {
return (
<ToastProvider>
<RootNavigator />
</ToastProvider>
);
}Import
typescript
import { toast } from 'reactnatively';Basic usage
SaveButton.tsx
1import { View, StyleSheet } from 'react-native';2import { toast, Button } from 'reactnatively';34export function SaveButton({ onSave }) {5 async function handleSave() {6 try {7 await onSave();8 toast.success('Changes saved!', { position: 'top' });9 } catch {10 toast.error('Failed to save. Try again.', {11 duration: 5000,12 action: { label: 'Retry', onPress: handleSave },13 });14 }15 }1617 return (18 <Button variant="solid" color="primary" onPress={handleSave}>19 Save Changes20 </Button>21 );22}All variants
ToastShowcase.tsx
1import { View, StyleSheet } from 'react-native';2import { toast, Button, Stack } from 'reactnatively';34export function ToastShowcase() {5 return (6 <Stack direction="vertical" gap={12} style={styles.container}>7 <Button variant="solid" color="success" onPress={() => toast.success('File uploaded successfully')}>8 Success toast9 </Button>10 <Button variant="solid" color="error" onPress={() => toast.error('Payment declined')}>11 Error toast12 </Button>13 <Button variant="solid" color="warning" onPress={() => toast.warning('Storage almost full')}>14 Warning toast15 </Button>16 <Button variant="outline" onPress={() => toast.info('New version available')}>17 Info toast18 </Button>19 <Button20 variant="glass"21 onPress={() =>22 toast.show({23 message: 'Message sent',24 type: 'success',25 glass: true,26 position: 'top',27 duration: 4000,28 action: { label: 'Undo', onPress: () => toast.info('Message unsent') },29 })30 }31 >32 Glass toast with action33 </Button>34 </Stack>35 );36}3738const styles = StyleSheet.create({39 container: { padding: 24 },40});API methods
| Method | Arguments | Default | Description |
|---|---|---|---|
| toast.show(opts) | ToastOptions | — | Show a toast with full options. |
| toast.success(msg, opts?) | string, Partial<ToastOptions> | — | Shorthand for type="success". |
| toast.error(msg, opts?) | string, Partial<ToastOptions> | — | Shorthand for type="error". |
| toast.warning(msg, opts?) | string, Partial<ToastOptions> | — | Shorthand for type="warning". |
| toast.info(msg, opts?) | string, Partial<ToastOptions> | — | Shorthand for type="info". |
ToastOptions
| Option | Type | Default | Description |
|---|---|---|---|
| message | string | — | The toast message text. |
| type | 'success' | 'error' | 'warning' | 'info' | 'default' | "default" | Semantic variant controlling icon and color. |
| duration | number | 3000 | Milliseconds before auto-dismiss. 0 = persistent. |
| position | 'top' | 'bottom' | "bottom" | Screen edge where toasts appear. |
| icon | ReactNode | undefined | Custom icon overriding the default type icon. |
| action | { label: string; onPress: () => void } | undefined | Inline action button inside the toast. |
| glass | boolean | false | Renders the toast on a glass surface. |