@teincfood/rn-notifications
v0.2.0
Published
React Native notification library for TeincFood — handles FCM push, Notifee, expo-notifications, badge sync, channels, tap handling, and push token registration out of the box.
Downloads
96
Readme
@teincfood/rn-notifications
React Native notification library for TeincFood — handles FCM push, Notifee, expo-notifications, badge sync, channels, tap handling, and push token registration out of the box.
Installation
npm install @teincfood/rn-notificationsPeer dependencies
Ensure the following are installed in your project:
expo >= 52@notifee/react-native >= 9@react-native-firebase/app >= 21@react-native-firebase/messaging >= 21expo-crypto >= 12expo-live-activity >= 0.4expo-notifications >= 0.28react >= 18react-native >= 0.72
Expo config plugin
Add to your app.config.js:
plugins: [
"@teincfood/rn-notifications",
// ... other plugins
]The plugin automatically configures:
expo-notificationswith 9 notification sounds@react-native-firebase/app(static frameworks)@react-native-firebase/messaging(static frameworks)expo-live-activity- Notifee Android Maven repo
- Android notification permissions (
POST_NOTIFICATIONS,WAKE_LOCK,RECEIVE_BOOT_COMPLETED) - iOS
remote-notificationbackground mode - Firebase manifest replacements for Android
Usage
1. Setup
Call setupNotifications once in your root _layout.tsx:
import { setupNotifications } from '@teincfood/rn-notifications';
import type { PushNotificationData, NotificationAction } from '@teincfood/rn-notifications';
import { api } from './services/api.service';
setupNotifications({
httpClient: api,
appType: 'buyer', // 'buyer' | 'business' | 'admin'
navigateToRoute: (route: string) => router.push(route),
onNotificationTapped: (payload: PushNotificationData) => {
// optional custom tap handling
},
onActionPress: (action: NotificationAction, payload: PushNotificationData) => {
// handle notification action button press
},
});2. Hooks
import {
useNotificationsList,
useUnreadCount,
useNotificationsMutations,
useNotificationsStream,
} from '@teincfood/rn-notifications';
// Fetch notifications
const { data, isLoading } = useNotificationsList();
// Get unread count
const { data: unreadCount } = useUnreadCount();
// Mutations (plain async functions — use try/catch or .catch)
const { markAsRead, markAllAsRead, removeNotification, clearAll } = useNotificationsMutations();
// Real-time stream (connect your app's events service to trigger refetch)
const { refetch } = useNotificationsList();
useNotificationsStream(
(cb) => {
const disconnect = eventsService.connect(userId);
const unsub = eventsService.on('notification_created', () => {
cb(); // triggers the stream
refetch(); // re-fetch notifications
});
return () => { unsub(); disconnect(); };
},
isAuthenticated,
);3. Notification sounds
9 .wav sounds are bundled and automatically configured by the Expo config plugin:
notification_default.wavorder_new.wavorder_status.wavorder_alert.wavorder_complete.wavorder_cancelled.wavrider_pickup.wavrider_opportunity.wavtimer_alert.wav
API
setupNotifications(options: SetupOptions)
Initializes the notification system. Options:
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| httpClient | HttpClient | Yes | HTTP client for API calls |
| appType | 'buyer' \| 'business' \| 'admin' | Yes | App type for token registration |
| navigateToRoute | (route: string) => void | No | Navigation callback on tap |
| onNotificationTapped | (payload: PushNotificationData) => void | No | Custom tap handler |
| onActionPress | (action: NotificationAction, payload: PushNotificationData) => void | No | Action button press handler |
NotificationsClient
Class with methods:
getNotifications()— fetch notification listgetUnreadCount()— fetch unread countmarkAsRead(id)— mark single notification as readmarkAllAsRead()— mark all as readremoveNotification(id)— remove a notificationdismissAction(id)— dismiss a notification actionclearAll()— clear all notificationssyncBadge()— sync native badge with server countclearBadge()— clear native badgegetPreferences()/updatePreferences(prefs)— notification preferences
Global singleton managed via setGlobalClient(client) / getGlobalClient().
License
MIT
