fgp-react-native-push-notifications
v1.0.0
Published
Native Firebase Cloud Messaging (FCM) push notifications library for React Native without Expo limits
Maintainers
Readme
fgp-react-native-push-notifications
Enterprise-Grade Firebase Cloud Messaging (FCM) Push & On-Device Local Notifications library for React Native and Expo. Operates without Expo Push Service limitations and fulfills Google Play 2027 Android Vitals standards.
🌟 Key Features
- ⚡ No Expo Limitations: Uses official native Firebase Messaging SDK directly.
- 💬 WhatsApp-Style Chat Notifications: Native
MessagingStylewith sender avatars (avatar_url) and Direct Reply. - 🖼️ Expandable Image Banners: Asynchronous image downloading (
BigPictureStyle) for rich media pushes. - 📞 Full-Screen Incoming Calls: Ringtone-activated
Full-Screen Intentwith "Accept" and "Decline" actions. - ⚙️ Custom Notification Channels:
createChannel()with custom importance, vibration, and sounds. - 🌐 Topic Subscriptions:
subscribeToTopic()andunsubscribeFromTopic(). - 🔔 100% Offline Local Notifications:
displayLocalNotification()for on-device alerts without a backend server or internet connection. - 🚀 Cold Start Payload Inspection:
getInitialNotification()retrieves launch payload when opening the app from a killed state.
📦 Installation
npm install fgp-react-native-push-notifications
# or
yarn add fgp-react-native-push-notifications⚙️ Android Configuration
1. AndroidManifest.xml Setup
Add the FCM service and Action Receiver inside your <application> tag:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<application>
<!-- FCM Native Service -->
<service
android:name="com.frankgp.pushnotifications.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- Broadcast Receiver for Direct Reply & Actions -->
<receiver
android:name="com.frankgp.pushnotifications.PushNotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.frankgp.pushnotifications.ACTION_CHAT_REPLY" />
<action android:name="com.frankgp.pushnotifications.ACTION_ACCEPT_CALL" />
<action android:name="com.frankgp.pushnotifications.ACTION_DECLINE_CALL" />
<action android:name="com.frankgp.pushnotifications.ACTION_MARK_READ" />
<action android:name="com.frankgp.pushnotifications.ACTION_MUTE" />
</intent-filter>
</receiver>
</application>
</manifest>2. Notification Icon Setup (app.json for Expo)
In your Expo app.json, specify your monochrome silhouette icon for Android status bar notifications:
{
"expo": {
"name": "MyAwesomeApp",
"android": {
"package": "com.example.app",
"googleServicesFile": "./google-services.json",
"notification": {
"icon": "./assets/images/notification-icon.png",
"color": "#208AEF"
}
}
}
}🚀 Usage Guide
import { PushNotification } from 'fgp-react-native-push-notifications';
// 1. Get Device FCM Registration Token
const token = await PushNotification.getFcmToken();
console.log('🔥 Device FCM Token:', token);
// 2. Create Custom Notification Channel
await PushNotification.createChannel({
id: 'vip_alerts',
name: 'VIP Alerts',
description: 'High importance notification channel',
importance: 'HIGH',
enableVibration: true,
});
// 3. Subscribe to Public Topic
await PushNotification.subscribeToTopic('global_announcements');
// 4. Display 100% Offline Local Notification
await PushNotification.displayLocalNotification({
title: 'Local Notification 🚀',
body: 'Generated directly on device without server or FCM network',
channelId: 'vip_alerts',
data: {
type: 'chat_message',
sender_name: 'Ana Sofia',
message_text: 'Hello from local notification!',
avatar_url: 'https://i.pravatar.cc/300?img=49',
},
});
// 5. Inspect Launch Notification Payload (Killed State)
const initialNotification = await PushNotification.getInitialNotification();
if (initialNotification) {
console.log('🚀 App launched via push payload:', initialNotification);
}
// 6. Listen for Foreground Push Messages
PushNotification.onMessage((notification) => {
console.log('🔔 Foreground Notification Received:', notification.title, notification.body);
});
// 7. Listen for Notification Taps
PushNotification.onNotificationOpenedApp((payload) => {
console.log('👆 User tapped notification:', payload);
});
// 8. Listen for Direct Reply & Button Actions
PushNotification.onAction((action) => {
console.log('🔘 Action Triggered:', action.actionId, action.replyText);
});🧪 HTTP Testing Suite
A complete REST Client test suite is available in api_notifications.http featuring test cases for:
- Google FCM HTTP v1 API (
https://fcm.googleapis.com/v1/projects/.../messages:send) - WhatsApp-style chat messages with live avatar URLs
- Full-screen incoming calls
- Expandable image banners
- Topic and condition-based messaging
📄 License
MIT © Frank GP
