@kevtucker/react-native-better-toast
v0.1.0
Published
A lightweight global toast component for React Native and Expo with variants, optional icons, and optional enter/exit animations.
Readme
@kevtucker/react-native-better-toast
A lightweight global toast component for React Native and Expo with variants, optional icons, and optional enter/exit animations.
Installation
yarn add @kevtucker/react-native-better-toastIf your app does not already include Expo vector icons, install them too:
yarn add @expo/vector-iconsQuick Start
Mount one toast host near the root of your app:
import { Toast } from '@kevtucker/react-native-better-toast';
export default function App() {
return (
<>
{/* Your app UI */}
<Toast position="top" />
</>
);
}Trigger toasts from anywhere:
import { Button } from 'react-native';
import { Toast } from '@kevtucker/react-native-better-toast';
export function SaveButton() {
return (
<Button
title="Show Toast"
onPress={() => {
Toast.success('You have successfully shown a toast!');
}}
/>
);
}API
Toast Host Props
Pass these props to the mounted host component:
duration?: numberdefault duration for all toasts (default:2500)position?: 'top' | 'bottom'default position for all toasts (default:'top')icon?: IoniconsName | null | falseglobal icon default; setfalseto disable icons globallytextColor?: stringglobal text color defaultanimated?: booleanenable enter/exit animations (default:true); setfalseto disable — recommended if you encounter animation issues on Expo SDK 55+
Global Methods
Toast.show(message, options?)Toast.show(optionsObject)Toast.success(message, options?)Toast.error(message, options?)Toast.info(message, options?)Toast.warning(message, options?)Toast.hide()
Show Options
message: stringvariant?: 'default' | 'success' | 'error' | 'info' | 'warning'duration?: numberposition?: 'top' | 'bottom'color?: stringcustom toast background colortextColor?: stringcustom toast text coloricon?: IoniconsName | null | falseoverride icon, setnullorfalseto hide iticonColor?: stringiconSize?: number
TypeScript
The package exports helpful types you can use in your app:
ToastPropsToastShowOptionsToastVariantToastPositionToastIconName
Example typed helper:
import {
Toast,
type ToastShowOptions,
type ToastVariant,
} from '@kevtucker/react-native-better-toast';
const showTypedToast = (variant: ToastVariant, message: string) => {
const options: ToastShowOptions = {
message,
variant,
duration: 2500,
position: 'top',
};
Toast.show(options);
};
showTypedToast('success', 'Profile updated');Examples
Toast.success('Saved successfully');
Toast.error('Upload failed', {
duration: 4000,
position: 'bottom',
});
Toast.show('Custom style', {
color: '#111827',
textColor: '#f9fafb',
icon: 'sparkles',
iconColor: '#fbbf24',
iconSize: 20,
});
Toast.show({
message: 'No icon toast',
variant: 'info',
icon: null,
});Disable all icons globally:
<Toast position="top" icon={false} />Disable animations (recommended for Expo SDK 55+):
<Toast position="top" animated={false} />Local Development (Without Publishing)
Use yalc to test this package in another app before publishing to npm.
In this library:
yarn yalc:publishIn your other app:
yalc add @kevtucker/react-native-better-toast
yarn installAfter library changes:
yarn yalc:pushIf Metro serves stale code:
expo start -cContributing
License
MIT
