Fully-customisable toast notifications for React Native apps
Lightweight β’ Animated β’ Lightning-fast β’ TypeScript-first
π Docs β’ π Quick Start β’ β¨ Features β’ β‘ Performance
See Rooster in action β’ Run locally β’ Explore the example app
β‘ 1-2ms renders | π¨ Fully customizable | βΏ WCAG 2.1 AA accessible | π± Responsive | π 100% TypeScript
Rooster handles the complex parts (safe areas, keyboard visibility, animations, accessibility) so you can focus on your app.
import { ToastProvider, useToast } from 'react-native-rooster';
export default function App() {
return (
<ToastProvider>
<YourApp />
</ToastProvider>
);
}
function YourApp() {
const { addToast } = useToast();
return (
<Button
onPress={() =>
addToast({
type: 'success',
title: 'Success!',
message: 'Your action completed.',
})
}
/>
);
}- 4 toast types: success, error, warning, info
- Smooth animations with native driver acceleration
- Elegant shadows and rounded corners
- Dynamic width for center positioning (respects screen size)
- Orientation-aware β adapts instantly on device rotation
- 6 position options (top/bottom Γ left/center/right)
- Smart keyboard avoidance
- WCAG 2.1 AA compliant
- Screen reader support with semantic roles
- Keyboard navigation (Escape to dismiss)
- Haptic feedback for tactile notifications
- Font scaling & contrast validation utilities
- 75-80% faster than v2 (1-2ms renders)
- Memory leak prevention
- Strategic memoization
- React Compiler compatible
- Tree-shakeable bundle (28-32 KB gzip)
- TypeScript strict mode
- Full type safety with JSDoc
- Composable & extensible
- Zero configuration needed
- Per-toast or global configuration
npm install react-native-rooster
# or
yarn add react-native-roosterRequires: React Native 0.60+ | TypeScript 4.0+
import { ToastProvider } from 'react-native-rooster';
export default function App() {
return (
<ToastProvider>
<YourApp />
</ToastProvider>
);
}import { useToast } from 'react-native-rooster';
function MyComponent() {
const { addToast } = useToast();
return (
<Button
onPress={() =>
addToast({
type: 'success',
title: 'Perfect!',
message: 'This is a toast notification.',
duration: 3000,
})
}
/>
);
}Positioning, animations, accessibility, and keyboard handling are automatic.
<ToastProvider
initialConfig={{
// Positioning
position: { vertical: 'bottom', horizontal: 'center' },
spacing: 12,
offset: 20,
// Styling
borderRadius: 12,
padding: { vertical: 16, horizontal: 16 },
shadow: { opacity: 0.2, offset: { width: 0, height: 12 } },
// Typography
font: {
titleFontSize: 16,
messageFontSize: 14,
},
// Timing
timeToDismiss: 3000,
// Accessibility
accessibility: {
allowFontScaling: true,
hapticFeedback: 'light',
},
}}
>
<App />
</ToastProvider>addToast({
type: 'success',
title: 'Success',
message: 'Your message here',
// Customization
backgroundColor: '#10b981',
duration: 2000,
onPress: () => console.log('Pressed'),
icon: <Icon />,
// Accessibility
accessibilityLabel: 'Success notification',
accessibilityHint: 'Double tap to dismiss',
hapticFeedback: 'success',
allowFontScaling: true,
});addToast({ type: 'success', message: 'All good!' }); // Green
addToast({ type: 'error', message: 'Oh no!' }); // Red
addToast({ type: 'warning', message: 'Watch out!' }); // Yellow
addToast({ type: 'info', message: 'FYI' }); // BlueAutomatic semantic announcements:
addToast({
type: 'success',
title: 'Payment Processed',
message: 'Order #12345 confirmed',
// Announces: "Success notification. Payment Processed. Order #12345 confirmed."
});- Web: Press Escape to dismiss
- iOS/Android: Standard accessibility gestures
addToast({
type: 'success',
message: 'Done!',
hapticFeedback: 'success', // Options: 'light', 'medium', 'success', 'error'
});<ToastProvider
initialConfig={{
accessibility: {
allowFontScaling: true, // Respects device text size settings
},
}}
>import { isContrastCompliant, hexToRgb } from 'react-native-rooster';
const text = [255, 255, 255]; // white
const bg = hexToRgb('#22c55e'); // green
if (isContrastCompliant(text, bg)) {
console.log('β
WCAG AA compliant');
}<ToastProvider
initialConfig={{
renderToast: ({ message, defaultToast }) => (
<MyCustomToastStyle>
{defaultToast}
</MyCustomToastStyle>
),
}}
>
<App />
</ToastProvider>import {
// Sizing
calculateToastHeight,
calculateResponsiveWidth,
// Accessibility
generateAccessibilityLabel,
generateAccessibilityHint,
calculateContrastRatio,
// Haptics
triggerHaptic,
HAPTIC_PATTERNS,
} from 'react-native-rooster';
// Example
const height = calculateToastHeight({ paddingVertical: 16 }, 2);
triggerHaptic('light');| Metric | v2 | v3.2.0 | Improvement |
|---|---|---|---|
| Render Time | 6-9ms | 1-2ms | 75-80% π |
| Click Response | 50ms+ | <5ms | 10x β‘ |
| Bundle Size | 32-36 KB | 28-32 KB | 15-20% π¦ |
| Memory Leaks | β Fixed | 100% π |
Optimizations in v3.2.0:
- β Memory leak prevention with animation cleanup
- β Strategic memoization throughout
- β Removed unnecessary re-render triggers
- β React Compiler compatible
const { addToast, removeToast, setToastConfig } = useToast();
// Add toast
addToast({ type: 'success', message: 'Done!' });
// Remove by ID or last toast
removeToast(id);
removeToast(); // Removes most recent
// Update config
setToastConfig({ timeToDismiss: 2000 });interface ToastMessage {
type?: 'success' | 'error' | 'warning' | 'info';
title?: string;
message: string;
icon?: ReactNode;
duration?: number;
onPress?: () => void;
style?: ViewStyle;
// Customization
backgroundColor?: string;
borderRadius?: number;
titleFontSize?: number;
messageFontSize?: number;
// Accessibility
accessibilityLabel?: string;
accessibilityHint?: string;
hapticFeedback?: 'light' | 'medium' | 'success' | 'error';
allowFontScaling?: boolean;
messageMaxLines?: number;
}- Memory leak prevention β animations cleanup on unmount
- Keyboard navigation β Escape key on web
- Haptic feedback β multi-sensory notifications
- Performance boost β 75-80% faster renders
- Better accessibility β WCAG 2.1 AA compliant
No breaking changes. All v3.0+ code works unchanged.
cd example
yarn install
yarn start
# Choose: i (iOS) or a (Android)We β€οΈ contributions!
git clone https://github.com/mCodex/react-native-rooster.git
cd react-native-rooster
yarn install
yarn example start
yarn lint
yarn test
yarn typecheckSee CONTRIBUTING.md for details.
No migration needed! v3 is 100% backward compatible with v2.
// Your v2 code works as-is
import { useToast } from 'react-native-rooster';
const { addToast } = useToast();
addToast({ type: 'success', message: 'Still works!' });- π Report Issue
- π¬ Discussions
- β GitHub
MIT Β© Mateus Andrade
Made with β€οΈ for the React Native community
β Star on GitHub β’ π Report Issue β’ π¬ Discussions
