Notification
Notification provides a toast notification system for displaying temporary messages.
Featuresβ
- π¨ Multiple types (success, error, warning, info)
- β±οΈ Auto-dismiss
- π― Custom content
- π Position control
- π§ Customizable styling
Basic Usageβ
import { Notification } from '@tansuk/rott-ui';
// Success notification
Notification.success('Changes saved successfully');
// Error notification
Notification.error('Something went wrong');
// Warning notification
Notification.warning('Please verify your email');
// Info notification
Notification.info('New update available');
Custom Notificationβ
Notification.custom({
title: 'Custom Title',
message: 'Custom message content',
icon: { name: 'STAR', variant: 'warning' },
duration: 5000,
});
Propsβ
The Notification component uses react-native-toast-notifications under the hood.
Static Methodsβ
| Method | Parameters | Description |
|---|---|---|
success | (message: string) | Show success toast |
error | (message: string) | Show error toast |
warning | (message: string) | Show warning toast |
info | (message: string) | Show info toast |
custom | (options) | Show custom toast |
Examplesβ
After Form Submitβ
const handleSubmit = async (values) => {
try {
await submitForm(values);
Notification.success('Form submitted successfully');
navigation.goBack();
} catch (error) {
Notification.error('Failed to submit form');
}
};
After Deleteβ
const handleDelete = async (id) => {
try {
await deleteItem(id);
Notification.success('Item deleted');
} catch (error) {
Notification.error('Failed to delete item');
}
};
Network Statusβ
import NetInfo from '@react-native-community/netinfo';
NetInfo.addEventListener(state => {
if (!state.isConnected) {
Notification.warning('No internet connection');
} else {
Notification.success('Connected to internet');
}
});
Custom with Iconβ
Notification.custom({
title: 'New Message',
message: 'You have a new message from John',
icon: { name: 'MAIL', variant: 'primary' },
duration: 4000,
});