Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit f42a581

Browse files
committed
Merge branch 'dev'
* dev: (28 commits) Release version 5.0.0. Fix behaviour of popInitialNotification and onNotification. Fix foreground value. fix popInitialNotification and null pointer Apply changes to popInitialNotification. make sure data/userInfo is an object before spreading keep notification data from fcm while populating data userInfo Fix case of small/large icon null. Add tests for channel update. #1549 Update CHANGELOG.md [Android] Allow to change default notification channel name after it's creation #1549 align onNotification on both platforms Rename `channelDesc` to `channelDescription`. Update code from recent PR for scheduled notifications return notification id in onNotification method on iOS populate userInfo with id on both platforms revert changes reflecting userInfo working on both platforms in documentation and example "@react-native-community/push-notification-ios": "^1.3.0" add data to android notification when scheduling Add docs for icon strings ... # Conflicts: # README.md
2 parents 9c34ed6 + 1f97855 commit f42a581

File tree

15 files changed

+311
-140
lines changed

15 files changed

+311
-140
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ android/src/main/gen
4646

4747
#Debug only
4848
google-services.json
49+
50+
.vscode/

CHANGELOG.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6-
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5+
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
76

87
## [Unreleased]
98

109
### Breaking changes
1110

11+
- (Android/iOS) Unify returned values between iOS and Android [#1516](https://github.com/zo0r/react-native-push-notification/pull/1516).
12+
- (Android/iOS) `.popInitialNotification(callback)` now return the same format as `onNotification()`.
13+
- (Android) `popInitialNotification` in `configure()` now trigger only once on app startup, same as iOS.
14+
- (Android) `notification.foreground` now return the good value, before the value was `false` most of the time.
15+
1216
### Features
1317

18+
- (Android) Add function `createChannel` for custom Android channel support [#1509](https://github.com/zo0r/react-native-push-notification/pull/1509)
19+
- (Android) Add Android `messageId` to enable integration with `react-native-firebase/messaging` [#1510](https://github.com/zo0r/react-native-push-notification/pull/1510)
20+
- (Android) Add support for `onlyAlertOnce` property [#1519](https://github.com/zo0r/react-native-push-notification/pull/1519)
21+
- (Android) Allow to change default notification channel name after it's creation [#1549](https://github.com/zo0r/react-native-push-notification/pull/1549)
22+
1423
### Fixed
1524

25+
- (Android) `popInitialNotification` in `configure()` now trigger only once and do not trigger twice `onNotification()` when user press the notification, more details: [#1516](https://github.com/zo0r/react-native-push-notification/pull/1516).
26+
- (Android) `notification.foreground` now return the good value, before the value was `false` most of the time.
1627

1728
## [4.0.0] 2020-07-06
1829

README.md

+42-11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
React Native Local and Remote Notifications for iOS and Android
77

88

9-
## 🎉 Version 4.0.0 is live ! 🎉
9+
## 🎉 Version 5.0.0 is live ! 🎉
1010

1111
Check out for changes in the CHANGELOG:
1212

1313
[Changelog](https://github.com/zo0r/react-native-push-notification/blob/master/CHANGELOG.md)
1414

15+
# Supporting the project
16+
17+
Maintaining this project takes time. To help allocate time, you can Buy Me a Coffee :wink:
18+
19+
<a href="https://www.buymeacoffee.com/Dallas62" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-blue.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
1520

1621
## Supported React Native Versions
1722

@@ -302,13 +307,12 @@ EXAMPLE:
302307
```javascript
303308
PushNotification.localNotification({
304309
/* Android Only Properties */
305-
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
306310
ticker: "My Notification Ticker", // (optional)
307311
showWhen: true, // (optional) default: true
308312
autoCancel: true, // (optional) default: true
309-
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
313+
largeIcon: "ic_launcher", // (optional) default: "ic_launcher". Use "" for no large icon.
310314
largeIconUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
311-
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
315+
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher". Use "" for default small icon.
312316
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
313317
subText: "This is a subText", // (optional) default: none
314318
bigPictureUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
@@ -327,18 +331,21 @@ PushNotification.localNotification({
327331
shortcutId: "shortcut-id", // (optional) If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut, default undefined
328332
channelId: "your-custom-channel-id", // (optional) custom channelId, if the channel doesn't exist, it will be created with options passed above (importance, vibration, sound). Once the channel is created, the channel will not be update. Make sure your channelId is different if you change these options. If you have created a custom channel, it will apply options of the channel.
329333
onlyAlertOnce: false, //(optional) alert will open only once with sound and notify, default: false
330-
334+
335+
messageId: "google:message_id", // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module.
336+
331337
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
332338
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
333339

334340
/* iOS only properties */
335341
alertAction: "view", // (optional) default: view
336342
category: "", // (optional) default: empty string
337-
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
338343

339344
/* iOS and Android properties */
345+
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
340346
title: "My Notification Title", // (optional)
341347
message: "My Notification Message", // (required)
348+
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
342349
playSound: false, // (optional) default: true
343350
soundName: "default", // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
344351
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
@@ -360,6 +367,18 @@ PushNotification.localNotificationSchedule({
360367
});
361368
```
362369

370+
## Get the initial notification
371+
372+
`PushNotification.popInitialNotification(callback)`
373+
374+
EXAMPLE:
375+
376+
```javascript
377+
PushNotification.popInitialNotification((notification) => {
378+
console.log('Initial Notification', notification);
379+
});
380+
```
381+
363382
## Custom sounds
364383

365384
In android, add your custom sound file to `[project_root]/android/app/src/main/res/raw`
@@ -372,7 +391,23 @@ In the location notification json specify the full file name:
372391

373392
## Channel Management (Android)
374393

375-
This library doesn't include a full Channel Management at the moment. Channels are generated on the fly when you pass options to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.
394+
To use custom channels, create them at startup and pass the matching `channelId` through to `PushNotification.localNotification`
395+
396+
```javascript
397+
PushNotification.createChannel(
398+
{
399+
channelId: "custom-channel-id", // (required)
400+
channelName: "Custom channel", // (required)
401+
channelDescription: "A custom channel to categorise your custom notifications", // (optional) default: undefined.
402+
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
403+
importance: 4, // (optional) default: 4. Int value of the Android notification importance
404+
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
405+
},
406+
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
407+
);
408+
```
409+
410+
Channels with ids that do not exist are generated on the fly when you pass options to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.
376411

377412
The pattern of `channel_id` is:
378413

@@ -647,10 +682,6 @@ Works natively in iOS.
647682

648683
Uses the [ShortcutBadger](https://github.com/leolin310148/ShortcutBadger) on Android, and as such will not work on all Android devices.
649684

650-
## Sending Notification Data From Server
651-
652-
Same parameters as `PushNotification.localNotification()`
653-
654685
## Android Only Methods
655686

656687
`PushNotification.subscribeToTopic(topic: string)` Subscribe to a topic (works only with Firebase)

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ private Bundle getBundleFromIntent(Intent intent) {
8989
public void onNewIntent(Intent intent) {
9090
Bundle bundle = this.getBundleFromIntent(intent);
9191
if (bundle != null) {
92-
bundle.putBoolean("foreground", false);
93-
intent.putExtra("notification", bundle);
9492
mJsDelivery.notifyNotification(bundle);
9593
}
9694
}
@@ -297,6 +295,18 @@ public void channelExists(String channel_id, Callback callback) {
297295
}
298296
}
299297

298+
@ReactMethod
299+
/**
300+
* Creates a channel if it does not already exist. Returns whether the channel was created.
301+
*/
302+
public void createChannel(ReadableMap channelInfo, Callback callback) {
303+
boolean created = mRNPushNotificationHelper.createChannel(channelInfo);
304+
305+
if(callback != null) {
306+
callback.invoke(created);
307+
}
308+
}
309+
300310
@ReactMethod
301311
/**
302312
* Check if channel is blocked with a given id

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationAttributes.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class RNPushNotificationAttributes {
3535
private static final String COLOR = "color";
3636
private static final String GROUP = "group";
3737
private static final String GROUP_SUMMARY = "groupSummary";
38-
private static final String USER_INTERACTION = "userInteraction";
38+
private static final String MESSAGE_ID = "messageId";
3939
private static final String PLAY_SOUND = "playSound";
4040
private static final String VIBRATE = "vibrate";
4141
private static final String VIBRATION = "vibration";
@@ -44,6 +44,7 @@ public class RNPushNotificationAttributes {
4444
private static final String TAG = "tag";
4545
private static final String REPEAT_TYPE = "repeatType";
4646
private static final String REPEAT_TIME = "repeatTime";
47+
private static final String ONLY_ALERT_ONCE = "onlyAlertOnce";
4748
private static final String ONGOING = "ongoing";
4849
private static final String ALLOW_WHILE_IDLE = "allowWhileIdle";
4950
private static final String IGNORE_IN_FOREGROUND = "ignoreInForeground";
@@ -70,6 +71,7 @@ public class RNPushNotificationAttributes {
7071
private final String color;
7172
private final String group;
7273
private final boolean groupSummary;
74+
private final String messageId;
7375
private final boolean userInteraction;
7476
private final boolean playSound;
7577
private final boolean vibrate;
@@ -79,6 +81,7 @@ public class RNPushNotificationAttributes {
7981
private final String tag;
8082
private final String repeatType;
8183
private final double repeatTime;
84+
private final boolean onlyAlertOnce;
8285
private final boolean ongoing;
8386
private final boolean allowWhileIdle;
8487
private final boolean ignoreInForeground;
@@ -106,7 +109,7 @@ public RNPushNotificationAttributes(Bundle bundle) {
106109
color = bundle.getString(COLOR);
107110
group = bundle.getString(GROUP);
108111
groupSummary = bundle.getBoolean(GROUP_SUMMARY);
109-
userInteraction = bundle.getBoolean(USER_INTERACTION);
112+
messageId = bundle.getString(MESSAGE_ID);
110113
playSound = bundle.getBoolean(PLAY_SOUND);
111114
vibrate = bundle.getBoolean(VIBRATE);
112115
vibration = bundle.getDouble(VIBRATION);
@@ -115,6 +118,7 @@ public RNPushNotificationAttributes(Bundle bundle) {
115118
tag = bundle.getString(TAG);
116119
repeatType = bundle.getString(REPEAT_TYPE);
117120
repeatTime = bundle.getDouble(REPEAT_TIME);
121+
onlyAlertOnce = bundle.getBoolean(ONLY_ALERT_ONCE);
118122
ongoing = bundle.getBoolean(ONGOING);
119123
allowWhileIdle = bundle.getBoolean(ALLOW_WHILE_IDLE);
120124
ignoreInForeground = bundle.getBoolean(IGNORE_IN_FOREGROUND);
@@ -144,7 +148,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
144148
color = jsonObject.has(COLOR) ? jsonObject.getString(COLOR) : null;
145149
group = jsonObject.has(GROUP) ? jsonObject.getString(GROUP) : null;
146150
groupSummary = jsonObject.has(GROUP_SUMMARY) ? jsonObject.getBoolean(GROUP_SUMMARY) : false;
147-
userInteraction = jsonObject.has(USER_INTERACTION) ? jsonObject.getBoolean(USER_INTERACTION) : false;
151+
messageId = jsonObject.has(MESSAGE_ID) ? jsonObject.getString(MESSAGE_ID) : null;
148152
playSound = jsonObject.has(PLAY_SOUND) ? jsonObject.getBoolean(PLAY_SOUND) : true;
149153
vibrate = jsonObject.has(VIBRATE) ? jsonObject.getBoolean(VIBRATE) : true;
150154
vibration = jsonObject.has(VIBRATION) ? jsonObject.getDouble(VIBRATION) : 1000;
@@ -153,6 +157,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
153157
tag = jsonObject.has(TAG) ? jsonObject.getString(TAG) : null;
154158
repeatType = jsonObject.has(REPEAT_TYPE) ? jsonObject.getString(REPEAT_TYPE) : null;
155159
repeatTime = jsonObject.has(REPEAT_TIME) ? jsonObject.getDouble(REPEAT_TIME) : 0.0;
160+
onlyAlertOnce = jsonObject.has(ONLY_ALERT_ONCE) ? jsonObject.getBoolean(ONLY_ALERT_ONCE) : false;
156161
ongoing = jsonObject.has(ONGOING) ? jsonObject.getBoolean(ONGOING) : false;
157162
allowWhileIdle = jsonObject.has(ALLOW_WHILE_IDLE) ? jsonObject.getBoolean(ALLOW_WHILE_IDLE) : false;
158163
ignoreInForeground = jsonObject.has(IGNORE_IN_FOREGROUND) ? jsonObject.getBoolean(IGNORE_IN_FOREGROUND) : false;
@@ -239,7 +244,7 @@ public Bundle toBundle() {
239244
bundle.putString(COLOR, color);
240245
bundle.putString(GROUP, group);
241246
bundle.putBoolean(GROUP_SUMMARY, groupSummary);
242-
bundle.putBoolean(USER_INTERACTION, userInteraction);
247+
bundle.putString(MESSAGE_ID, messageId);
243248
bundle.putBoolean(PLAY_SOUND, playSound);
244249
bundle.putBoolean(VIBRATE, vibrate);
245250
bundle.putDouble(VIBRATION, vibration);
@@ -248,6 +253,7 @@ public Bundle toBundle() {
248253
bundle.putString(TAG, tag);
249254
bundle.putString(REPEAT_TYPE, repeatType);
250255
bundle.putDouble(REPEAT_TIME, repeatTime);
256+
bundle.putBoolean(ONLY_ALERT_ONCE, onlyAlertOnce);
251257
bundle.putBoolean(ONGOING, ongoing);
252258
bundle.putBoolean(ALLOW_WHILE_IDLE, allowWhileIdle);
253259
bundle.putBoolean(IGNORE_IN_FOREGROUND, ignoreInForeground);
@@ -279,7 +285,7 @@ public JSONObject toJson() {
279285
jsonObject.put(COLOR, color);
280286
jsonObject.put(GROUP, group);
281287
jsonObject.put(GROUP_SUMMARY, groupSummary);
282-
jsonObject.put(USER_INTERACTION, userInteraction);
288+
jsonObject.put(MESSAGE_ID, messageId);
283289
jsonObject.put(PLAY_SOUND, playSound);
284290
jsonObject.put(VIBRATE, vibrate);
285291
jsonObject.put(VIBRATION, vibration);
@@ -288,6 +294,7 @@ public JSONObject toJson() {
288294
jsonObject.put(TAG, tag);
289295
jsonObject.put(REPEAT_TYPE, repeatType);
290296
jsonObject.put(REPEAT_TIME, repeatTime);
297+
jsonObject.put(ONLY_ALERT_ONCE, onlyAlertOnce);
291298
jsonObject.put(ONGOING, ongoing);
292299
jsonObject.put(ALLOW_WHILE_IDLE, allowWhileIdle);
293300
jsonObject.put(IGNORE_IN_FOREGROUND, ignoreInForeground);
@@ -325,6 +332,7 @@ public String toString() {
325332
", color='" + color + '\'' +
326333
", group='" + group + '\'' +
327334
", groupSummary='" + groupSummary + '\'' +
335+
", messageId='" + messageId + '\'' +
328336
", userInteraction=" + userInteraction +
329337
", playSound=" + playSound +
330338
", vibrate=" + vibrate +
@@ -334,6 +342,7 @@ public String toString() {
334342
", tag='" + tag + '\'' +
335343
", repeatType='" + repeatType + '\'' +
336344
", repeatTime=" + repeatTime +
345+
", onlyAlertOnce=" + onlyAlertOnce +
337346
", ongoing=" + ongoing +
338347
", allowWhileIdle=" + allowWhileIdle +
339348
", ignoreInForeground=" + ignoreInForeground +

0 commit comments

Comments
 (0)