rn-firebase-notifications-kit 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/package.json +1 -1
- package/src/core.js +21 -5
- package/src/index.d.ts +7 -0
package/README.md
CHANGED
|
@@ -261,6 +261,8 @@ Call once in `index.js`, before `AppRegistry.registerComponent`.
|
|
|
261
261
|
| `channels` | `[{ id: 'default', name: 'General' }]` | Android channels. See [Channels](#channels-android). |
|
|
262
262
|
| `defaultChannel` | first channel | Channel for messages that name none. |
|
|
263
263
|
| `smallIcon`, `color` | — | Android small icon resource name and accent colour for every notification. |
|
|
264
|
+
| `decorate(n, payload)` | — | Change the Notifee payload before display (image, actions, style). Return the new payload. |
|
|
265
|
+
| `onEvent(event, { state, notification })` | — | Receives every Notifee event, e.g. action-button presses and dismissals. |
|
|
264
266
|
| `display` | `true` | Show data-only messages as notifications. |
|
|
265
267
|
| `onMessage(n, remoteMessage)` | — | Runs for every background / killed-state message, before it is displayed. Keep it short; Android gives a headless task limited time. |
|
|
266
268
|
|
|
@@ -293,6 +295,16 @@ Call once after the app mounts.
|
|
|
293
295
|
|
|
294
296
|
TypeScript types are included.
|
|
295
297
|
|
|
298
|
+
## Pro
|
|
299
|
+
|
|
300
|
+
The free kit gets push working in every app state. **Pro** adds what most apps build next:
|
|
301
|
+
|
|
302
|
+
- **Notification inbox** — saved history with read / unread state, a ready `<InboxScreen />` and a `useInbox()` hook
|
|
303
|
+
- **Rich notifications** — images, action buttons, inline reply and chat-style stacking
|
|
304
|
+
- **Server code** — a Node.js sender with auth, retry, dead-token cleanup and bulk sends
|
|
305
|
+
|
|
306
|
+
Pro is a private repository for monthly sponsors: **$15 a month** on GitHub Sponsors, unlimited apps, every update while you sponsor, and versions you received stay yours. **[Get Pro →](https://github.com/sponsors/hanif-2000)**
|
|
307
|
+
|
|
296
308
|
## Limits
|
|
297
309
|
|
|
298
310
|
- **It cannot do the native setup for you.** You still need a Firebase project, the config files and an APNs key. `doctor` finds what is missing in your files; it cannot see your Firebase console.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-firebase-notifications-kit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Firebase push notifications for React Native in two calls: foreground, background and killed state, one tap handler for all three, plus a doctor command that checks your native setup. Built on React Native Firebase Messaging and Notifee.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/core.js
CHANGED
|
@@ -58,7 +58,7 @@ export function createPushKit(deps) {
|
|
|
58
58
|
const seenOpens = new Set(); // one tap can be reported by two APIs; deliver it once
|
|
59
59
|
const channelsReady = new Set();
|
|
60
60
|
// Shared by registerBackgroundHandler() and setupPush(): define channels once, in index.js.
|
|
61
|
-
const config = { channels: [DEFAULT_CHANNEL], defaultChannel: DEFAULT_CHANNEL.id, smallIcon: undefined, color: undefined };
|
|
61
|
+
const config = { channels: [DEFAULT_CHANNEL], defaultChannel: DEFAULT_CHANNEL.id, smallIcon: undefined, color: undefined, decorate: undefined, onEvent: undefined };
|
|
62
62
|
|
|
63
63
|
function importanceOf(value) {
|
|
64
64
|
if (typeof value === 'number') return value;
|
|
@@ -83,6 +83,8 @@ export function createPushKit(deps) {
|
|
|
83
83
|
}
|
|
84
84
|
if (options.smallIcon !== undefined) config.smallIcon = options.smallIcon;
|
|
85
85
|
if (options.color !== undefined) config.color = options.color;
|
|
86
|
+
if (options.decorate !== undefined) config.decorate = options.decorate;
|
|
87
|
+
if (options.onEvent !== undefined) config.onEvent = options.onEvent;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
/** Create every configured channel, so they all appear in the system settings from first launch. */
|
|
@@ -114,12 +116,22 @@ export function createPushKit(deps) {
|
|
|
114
116
|
const smallIcon = channel.smallIcon ?? config.smallIcon;
|
|
115
117
|
if (smallIcon) android.smallIcon = smallIcon;
|
|
116
118
|
if (config.color) android.color = config.color;
|
|
117
|
-
|
|
119
|
+
const payload = {
|
|
118
120
|
title: notification.title ?? undefined,
|
|
119
121
|
body: notification.body ?? undefined,
|
|
120
122
|
data,
|
|
121
123
|
android,
|
|
122
|
-
}
|
|
124
|
+
};
|
|
125
|
+
// Extension point: `decorate` may return a changed payload (images, actions, styles).
|
|
126
|
+
const decorated = config.decorate ? await config.decorate(notification, payload) : payload;
|
|
127
|
+
await notifee.displayNotification(decorated ?? payload);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Extension point: every Notifee event is also passed to `onEvent`, with the notification in this kit's shape. */
|
|
131
|
+
async function forwardEvent(event, state) {
|
|
132
|
+
if (!config.onEvent) return;
|
|
133
|
+
const notification = event?.detail?.notification ? normalizeDisplayed(event.detail.notification) : null;
|
|
134
|
+
await config.onEvent(event, { state, notification });
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
function emitOpen(notification, state) {
|
|
@@ -219,10 +231,12 @@ export function createPushKit(deps) {
|
|
|
219
231
|
}
|
|
220
232
|
});
|
|
221
233
|
|
|
222
|
-
notifee.onBackgroundEvent(async (
|
|
234
|
+
notifee.onBackgroundEvent(async (event) => {
|
|
235
|
+
const { type, detail } = event;
|
|
223
236
|
if (type === EventType.PRESS && detail?.notification) {
|
|
224
237
|
emitOpen(normalizeDisplayed(detail.notification), 'background');
|
|
225
238
|
}
|
|
239
|
+
await forwardEvent(event, 'background');
|
|
226
240
|
});
|
|
227
241
|
}
|
|
228
242
|
|
|
@@ -288,10 +302,12 @@ export function createPushKit(deps) {
|
|
|
288
302
|
}));
|
|
289
303
|
|
|
290
304
|
// Tap on a notification this kit displayed, while the app is in the foreground.
|
|
291
|
-
unsubscribers.push(notifee.onForegroundEvent((
|
|
305
|
+
unsubscribers.push(notifee.onForegroundEvent((event) => {
|
|
306
|
+
const { type, detail } = event;
|
|
292
307
|
if (type === EventType.PRESS && detail?.notification) {
|
|
293
308
|
emitOpen(normalizeDisplayed(detail.notification), 'foreground');
|
|
294
309
|
}
|
|
310
|
+
forwardEvent(event, 'foreground').catch(report);
|
|
295
311
|
}));
|
|
296
312
|
|
|
297
313
|
openListener = handleOpen;
|
package/src/index.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface PushConfig {
|
|
|
31
31
|
smallIcon?: string;
|
|
32
32
|
/** Android accent colour, e.g. '#17BE00'. */
|
|
33
33
|
color?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Change the Notifee payload before a notification is displayed (add an image, actions, a style).
|
|
36
|
+
* Return the new payload, or nothing to keep the original.
|
|
37
|
+
*/
|
|
38
|
+
decorate?: (notification: PushNotification, payload: Record<string, any>) => Record<string, any> | void | Promise<Record<string, any> | void>;
|
|
39
|
+
/** Receives every Notifee event (action presses, dismissals, ...) in foreground and background. */
|
|
40
|
+
onEvent?: (event: { type: number; detail: Record<string, any> }, info: { state: 'foreground' | 'background'; notification: PushNotification | null }) => void | Promise<void>;
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
export type AppState = 'foreground' | 'background' | 'quit';
|