There are some cases when local notification action should be handled in
background eg. snoozing the reminder. In case of it launching app UI is
not necessary and would be confusing for the end user.
Therefore there should be a way to handle local notification action in
background.
For this reason new property 'runInBackground' was added to the
AndroidAction class and TypeScript type.
Also new broadcast receiver and service were implemented to handle
properly background actions.
In order to run particular action in background API consumer need to set its
'runInBackground' property to 'true', eg:
...
.android.addAction(new firebase.notifications.Android.Action("snooze",
"ic_snooze", "Snooze").setRunInBackground(true))
...
Then, there are two cases that API consumer needs to handle.
First when app is in the foreground, standard notification and
notification action code path will be executed. This mean, that:
* onNotification() listener will be called (which should call
displayNotification(), in order to show it to the user),
* onNotificationOpen() listener will be called after the action is
tapped by the user
Secondly, when application is in background or it is not running new
'RNFirebaseBackgroundNotificationAction' handler will be called. To
properly handle this case API consumer should create a background
asynchronous handler:
const handleAsyncTask = async (notificationOpen: NotifficationOpen) => {
if (notificationOpen && notificationOpen.notification) {
const action = notificationOpen.action;
const notificationId = notificationOpen.notification.notificationId;
if (action === "snooze") {
console.log("Reschedule notification for later time", notificationId);
} else {
console.log("unsupported action", action);
}
// hide the notification
firebase.notifications().removeDeliveredNotification(notificationId);
}
}
Next hander should be registered to headless handler:
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundNotificationAction', () => handleAsyncTask);
Finally AndroidManifest.xml file must be modified, to include receiver
and service definition:
<receiver
android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
android:exported="true">
<intent-filter>
<action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
</intent-filter>
</receiver>
<service android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionsService"/>
Now when ever 'Snooze' action is pressed it will launch
'handleAsyncTask' function in the background or onNotificationOpen()
when app is in foreground. And reschedule the notification
for the later time.
React Native Firebase
Introduction
RNFirebase makes using Firebase with React Native simple. It is a light-weight layer sitting on-top of the native Firebase libraries for both iOS and Android which mirrors the Firebase Web SDK as closely as possible.
Although the Firebase Web SDK library will work with React Native, it is mainly built for the web.
RNFirebase provides a JavaScript bridge to the native Firebase SDKs for both iOS and Android therefore Firebase will run on the native thread, allowing the rest of your app to run on the JS thread. The Firebase Web SDK also runs on the JS thread, therefore potentially affecting the frame rate causing jank with animations, touch events etc.
The native SDKs also allow us to hook into device sdk's which are not possible with the web SDK, for example crash reporting, offline realtime database support, analytics and more!
All in all, RNFirebase provides much faster performance (~2x) over the web SDK and provides device sdk's not found in the web sdk (see the feature table below).
Supported Firebase Features
The Web SDK column indicates what modules/functionality from the Web SDK are usable within React Native.
'?' indicates partial support
| Firebase Features | v2.2.x | v3.3.x | v4.0.x | Web SDK |
|---|---|---|---|---|
| AdMob | ✅ | ✅ | ✅ | ❌ |
| Analytics | ✅ | ✅ | ✅ | ❌ |
| App Indexing | ❌ | ❌ | ❌ | ❌ |
| Authentication | ✅ | ✅ | ✅ | ✅ |
| -- Phone Auth | ❌ | ✅ | ✅ | ❌ |
| Core | ? | ✅ | ✅ | ✅ |
| -- Multiple Apps | ❌ | ✅ | ✅ | ✅ |
| Cloud Firestore | ❌ | ✅ | ✅ | ? |
| Cloud Messaging (FCM) | ? | ? | ✅ | ❌ |
| Crashlytics | ❌ | ✅ | ✅ | ❌ |
| Crash Reporting | ✅ | ✅ | ✅ | ❌ |
| Dynamic Links | ❌ | ✅ | ✅ | ❌ |
| Functions Callable | ❌ | ❌ | ✅ | ✅ |
| Invites | ❌ | ❌ | ✅ | ❌ |
| Instance ID | ❌ | ❌ | ? | ❌ |
| Performance Monitoring | ✅ | ✅ | ✅ | ❌ |
| Realtime Database | ✅ | ✅ | ✅ | ✅ |
| -- Offline Persistence | ✅ | ✅ | ✅ | ? |
| Remote Config | ✅ | ✅ | ✅ | ❌ |
| Storage | ✅ | ✅ | ✅ | ? |
Supported versions - React Native / Firebase
The table below shows the supported versions of React Native and the Firebase SDKs for different versions of
react-native-firebase
| 2.2.x | 3.3.x | 4.0.x | |
|---|---|---|---|
| React Native | 0.47 + | 0.50 + | 0.52 + |
| Firebase Android SDK | 11.0.0 + | 11.8.0 + | 12.0.0 + |
| Firebase iOS SDK | 4.0.0 + | 4.7.0 + | 4.11.0 + |
Documentation
To check out our latest docs, visit rnfirebase.io
Questions
For questions and support please use our Discord chat or Stack Overflow. The issue list of this repo is exclusively for bug reports.
Issues
Please make sure to complete the issue template before opening an issue. Issues not conforming to the guidelines may be closed immediately.
Feature Requests
For feature requests please use our Canny Board.
Changelog
Detailed changes for each release are documented in the releases notes.
Supporting RNFirebase
RNFirebase is an Apache-2.0 licensed open source project. It's an independent project with its ongoing development made possible entirely thanks to the support by these awesome sponsors and backers. If you'd like to join them, please consider:
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
Backers
Thank you to all our backers! 🙏 [Become a backer]
Contributing
Please make sure to read the Contributing Guide before making a pull request.
Thank you to all the people who have already contributed to RNFirebase!
License
- See LICENSE
