@chain1/toast-service
v1.0.1
Published
Toast notification service for React Native with queue management and history
Downloads
5
Maintainers
Readme
@chain1/toast-service
Toast notification service for React Native with queue management and persistent history.
Installation
npm install @chain1/toast-service
npm install @react-native-async-storage/async-storage i18nextFeatures
- 🔔 Queue Management - Sequential toast display with automatic queuing
- 📝 Persistent History - Save and retrieve toast history
- 🌍 i18n Support - Internationalization ready
- 🎨 Multiple Types - Success, error, warning, info, and custom types
- 💰 Reward Toasts - Built-in support for referral, level, and weekly rewards
Usage
Basic Usage
import toastService from '@chain1/toast-service';
// Show simple messages
toastService.showSuccess('Operation completed!');
toastService.showError('Something went wrong');
toastService.showInfo('New update available');
toastService.showWarning('Please check your input');
// Custom toast
toastService.showToast('Title', 'Message content', 'info');Reward Notifications
// Referral reward
toastService.showReferralReward(1000, 'user123');
// Level achievement reward
toastService.showLevelReward(5, 500);
// Weekly reward
toastService.showWeeklyReward(2000, 'Week 42');Queue Management
// Multiple toasts will be queued and shown sequentially
toastService.showSuccess('First message');
toastService.showInfo('Second message');
toastService.showWarning('Third message');
// Clear pending queue
toastService.clearToastQueue();
// Check status
const status = toastService.getStatus();
console.log(status);
// {
// isShowingToast: false,
// queueLength: 0,
// historyLength: 5,
// lastToast: { ... }
// }History Management
// Get toast history (default: last 20)
const history = toastService.getToastHistory(20);
// Get all history
const allHistory = toastService.getToastHistory(50);
// Clear history
await toastService.clearToastHistory();
// Load history from storage
await toastService.loadToastHistory();API Reference
Methods
showToast(title, message, type)
Display a custom toast message.
Parameters:
title(string) - Toast titlemessage(string) - Toast messagetype(ToastType) - Toast type (optional, default: 'info')
showSuccess(message)
Show a success toast.
showError(message)
Show an error toast.
showInfo(message)
Show an info toast.
showWarning(message)
Show a warning toast.
showReferralReward(amount, referrerId?)
Show a referral reward toast.
showLevelReward(level, amount)
Show a level achievement reward toast.
showWeeklyReward(amount, weekInfo?)
Show a weekly reward toast.
getToastHistory(limit?)
Get toast history.
Parameters:
limit(number) - Number of items to return (default: 20)
Returns: ToastData[]
clearToastHistory()
Clear all toast history.
loadToastHistory()
Load toast history from AsyncStorage.
getStatus()
Get current toast service status.
Returns: ToastStatus
clearToastQueue()
Clear pending toast queue.
Types
type ToastType =
| 'info'
| 'success'
| 'error'
| 'warning'
| 'referral_reward'
| 'level_reward'
| 'weekly_reward';
interface ToastData {
title: string;
message: string;
type: ToastType;
timestamp: string;
id: string;
}
interface ToastStatus {
isShowingToast: boolean;
queueLength: number;
historyLength: number;
lastToast: ToastData | null;
}Peer Dependencies
react-native>= 0.60.0@react-native-async-storage/async-storage>= 1.0.0i18next>= 20.0.0
License
MIT
Author
webcgi
