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

Commit 3641bf6

Browse files
committed
Release 7.0.0
1 parent 469c167 commit 3641bf6

File tree

7 files changed

+109
-43
lines changed

7 files changed

+109
-43
lines changed

CHANGELOG.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
88

99
### Breaking changes
1010

11+
### Features
12+
13+
### Fixed
14+
15+
## [7.0.0] 2020-12-23
16+
17+
### Breaking changes
18+
1119
- (iOS) Replace deprecated local notification methods on iOS [1751](https://github.com/zo0r/react-native-push-notification/pull/1751)
1220
- (Android) Rename the Android package from `ReactNativePushNotification` to `ReactNativePushNotification` resolve [893](https://github.com/zo0r/react-native-push-notification/issues/893)
21+
- (Android) Allow `userInfo` to be stored in scheduled notification as in iOS (mapped as `data` on press or list scheduled notifications).
1322

1423
### Features
1524

25+
- (Android) silent channel using playSound flag
1626
- (Android) implement 'bigLargeIcon' for Android notifications (must be combined with BigPicture) [#1730](https://github.com/zo0r/react-native-push-notification/pull/1730)
1727
- (Android) notification with inline reply [#612](https://github.com/zo0r/react-native-push-notification/pull/612)
18-
19-
### Fixed
28+
- (Android) Support using drawable as Android small icon [#1787](https://github.com/zo0r/react-native-push-notification/pull/1787)
2029

2130
## [6.1.3] 2020-11-09
2231

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,6 @@ Make sure you have the receiver in `AndroidManifest.xml`:
653653
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
654654
```
655655

656-
For iOS, you can use this [package](https://github.com/holmesal/react-native-ios-notification-actions) to add notification actions.
657-
658656
Notifications with inline reply:
659657

660658
You must register an action as "ReplyInput", this will show in the notifications an input to write in.
@@ -678,7 +676,17 @@ if(notification.action === "ReplyInput"){
678676
console.log("texto", notification.reply_text)// this will contain the inline reply text.
679677
}
680678
...
679+
```
680+
681+
For iOS, you can use:
682+
683+
```javascript
684+
PushNotification.setNotificationCategories(categories);
685+
```
686+
687+
And use the `category` field in the notification.
681688

689+
Documentation [here](https://github.com/react-native-push-notification-ios/push-notification-ios#how-to-perform-different-action-based-on-user-selected-action) to add notification actions.
682690

683691
## Set application badge icon
684692

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

+54-32
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.json.JSONException;
1111
import org.json.JSONObject;
1212

13+
import java.util.Iterator;
14+
1315
import static com.dieam.reactnativepushnotification.modules.RNPushNotification.LOG_TAG;
1416

1517
public class RNPushNotificationAttributes {
@@ -51,6 +53,7 @@ public class RNPushNotificationAttributes {
5153
private static final String REPLAY_PLACEHOLDER_TEXT = "reply_placeholder_text";
5254
private static final String ALLOW_WHILE_IDLE = "allowWhileIdle";
5355
private static final String IGNORE_IN_FOREGROUND = "ignoreInForeground";
56+
private static final String USER_INFO = "userInfo";
5457

5558
private final String id;
5659
private final String message;
@@ -90,6 +93,7 @@ public class RNPushNotificationAttributes {
9093
private final String reply_placeholder_text;
9194
private final boolean allowWhileIdle;
9295
private final boolean ignoreInForeground;
96+
private final String userInfo;
9397

9498
public RNPushNotificationAttributes(Bundle bundle) {
9599
id = bundle.getString(ID);
@@ -130,6 +134,7 @@ public RNPushNotificationAttributes(Bundle bundle) {
130134
reply_placeholder_text = bundle.getString(REPLAY_PLACEHOLDER_TEXT);
131135
allowWhileIdle = bundle.getBoolean(ALLOW_WHILE_IDLE);
132136
ignoreInForeground = bundle.getBoolean(IGNORE_IN_FOREGROUND);
137+
userInfo = bundle.getString(USER_INFO);
133138
}
134139

135140
private RNPushNotificationAttributes(JSONObject jsonObject) {
@@ -172,6 +177,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
172177
reply_placeholder_text = jsonObject.has(REPLAY_PLACEHOLDER_TEXT) ? jsonObject.getString(REPLAY_PLACEHOLDER_TEXT) : null;
173178
allowWhileIdle = jsonObject.has(ALLOW_WHILE_IDLE) ? jsonObject.getBoolean(ALLOW_WHILE_IDLE) : false;
174179
ignoreInForeground = jsonObject.has(IGNORE_IN_FOREGROUND) ? jsonObject.getBoolean(IGNORE_IN_FOREGROUND) : false;
180+
userInfo = jsonObject.has(USER_INFO) ? jsonObject.getString(USER_INFO) : null;
175181
} catch (JSONException e) {
176182
throw new IllegalStateException("Exception while initializing RNPushNotificationAttributes from JSON", e);
177183
}
@@ -180,6 +186,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
180186
@NonNull
181187
public static RNPushNotificationAttributes fromJson(String notificationAttributesJson) throws JSONException {
182188
JSONObject jsonObject = new JSONObject(notificationAttributesJson);
189+
183190
return new RNPushNotificationAttributes(jsonObject);
184191
}
185192

@@ -191,41 +198,49 @@ public static RNPushNotificationAttributes fromJson(String notificationAttribute
191198
* @return true all fields in userInfo object match, false otherwise
192199
*/
193200
public boolean matches(ReadableMap userInfo) {
194-
Bundle bundle = toBundle();
201+
try {
202+
if(this.userInfo == null) {
203+
return false;
204+
}
205+
206+
JSONObject jsonObject = new JSONObject(this.userInfo);
195207

196-
ReadableMapKeySetIterator iterator = userInfo.keySetIterator();
197-
while (iterator.hasNextKey()) {
198-
String key = iterator.nextKey();
208+
ReadableMapKeySetIterator iterator = userInfo.keySetIterator();
209+
while (iterator.hasNextKey()) {
210+
String key = iterator.nextKey();
199211

200-
if (!bundle.containsKey(key))
201-
return false;
212+
if (!jsonObject.has(key))
213+
return false;
202214

203-
switch (userInfo.getType(key)) {
204-
case Null: {
205-
if (bundle.get(key) != null)
206-
return false;
207-
break;
208-
}
209-
case Boolean: {
210-
if (userInfo.getBoolean(key) != bundle.getBoolean(key))
211-
return false;
212-
break;
213-
}
214-
case Number: {
215-
if ((userInfo.getDouble(key) != bundle.getDouble(key)) && (userInfo.getInt(key) != bundle.getInt(key)))
216-
return false;
217-
break;
218-
}
219-
case String: {
220-
if (!userInfo.getString(key).equals(bundle.getString(key)))
221-
return false;
222-
break;
223-
}
224-
case Map:
225-
return false;//there are no maps in the bundle
226-
case Array:
227-
return false;//there are no arrays in the bundle
228-
}
215+
switch (userInfo.getType(key)) {
216+
case Null: {
217+
if (jsonObject.get(key) != null)
218+
return false;
219+
break;
220+
}
221+
case Boolean: {
222+
if (userInfo.getBoolean(key) != jsonObject.getBoolean(key))
223+
return false;
224+
break;
225+
}
226+
case Number: {
227+
if ((userInfo.getDouble(key) != jsonObject.getDouble(key)) && (userInfo.getInt(key) != jsonObject.getInt(key)))
228+
return false;
229+
break;
230+
}
231+
case String: {
232+
if (!userInfo.getString(key).equals(jsonObject.getString(key)))
233+
return false;
234+
break;
235+
}
236+
case Map:
237+
return false;//there are no maps in the jsonObject
238+
case Array:
239+
return false;//there are no arrays in the jsonObject
240+
}
241+
}
242+
} catch(JSONException e) {
243+
return false;
229244
}
230245

231246
return true;
@@ -271,6 +286,7 @@ public Bundle toBundle() {
271286
bundle.putString(REPLAY_PLACEHOLDER_TEXT, reply_placeholder_text);
272287
bundle.putBoolean(ALLOW_WHILE_IDLE, allowWhileIdle);
273288
bundle.putBoolean(IGNORE_IN_FOREGROUND, ignoreInForeground);
289+
bundle.putString(USER_INFO, userInfo);
274290
return bundle;
275291
}
276292

@@ -315,6 +331,7 @@ public JSONObject toJson() {
315331
jsonObject.put(REPLAY_PLACEHOLDER_TEXT, reply_placeholder_text);
316332
jsonObject.put(ALLOW_WHILE_IDLE, allowWhileIdle);
317333
jsonObject.put(IGNORE_IN_FOREGROUND, ignoreInForeground);
334+
jsonObject.put(USER_INFO, userInfo);
318335
} catch (JSONException e) {
319336
Log.e(LOG_TAG, "Exception while converting RNPushNotificationAttributes to " +
320337
"JSON. Returning an empty object", e);
@@ -365,6 +382,7 @@ public String toString() {
365382
", reply_placeholder_text=" + reply_placeholder_text +
366383
", allowWhileIdle=" + allowWhileIdle +
367384
", ignoreInForeground=" + ignoreInForeground +
385+
", userInfo=" + userInfo +
368386
'}';
369387
}
370388

@@ -388,6 +406,10 @@ public String getNumber() {
388406
return number;
389407
}
390408

409+
public String getUserInfo() {
410+
return userInfo;
411+
}
412+
391413
public String getRepeatType() {
392414
return repeatType;
393415
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
431431
if (!bundle.containsKey("playSound") || bundle.getBoolean("playSound")) {
432432
String soundName = bundle.getString("soundName");
433433

434-
if (soundName == null) {
435-
soundName = "default";
436-
}
437-
438434
soundUri = getSoundUri(soundName);
439435

440436
notification.setSound(soundUri);
@@ -772,6 +768,7 @@ public WritableArray getScheduledLocalNotifications() {
772768
notificationMap.putString("id", notification.getId());
773769
notificationMap.putString("repeatInterval", notification.getRepeatType());
774770
notificationMap.putString("soundName", notification.getSound());
771+
notificationMap.putString("data", notification.getUserInfo());
775772

776773
scheduled.pushMap(notificationMap);
777774
} catch (JSONException e) {

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@react-native-community/push-notification-ios": "^1.4.0",
1515
"react": "16.13.1",
1616
"react-native": "0.63.3",
17-
"react-native-push-notification": "lluis-sancho/react-native-push-notification"
17+
"react-native-push-notification": "zo0r/react-native-push-notification#master"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.9.0",

index.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ Notifications.localNotification = function(details) {
210210
if(details && Array.isArray(details.actions)) {
211211
details.actions = JSON.stringify(details.actions);
212212
}
213+
214+
if(details.userInfo) {
215+
details.userInfo = JSON.stringify(details.userInfo);
216+
}
213217

214218
this.handler.presentLocalNotification(details);
215219
}
@@ -289,6 +293,10 @@ Notifications.localNotificationSchedule = function(details) {
289293
details.actions = JSON.stringify(details.actions);
290294
}
291295

296+
if(details.userInfo) {
297+
details.userInfo = JSON.stringify(details.userInfo);
298+
}
299+
292300
details.fireDate = details.date.getTime();
293301
delete details.date;
294302
// ignore iOS only repeatType
@@ -360,6 +368,8 @@ Notifications._transformNotificationObject = function(data, isFromBackground = n
360368
title: data.getTitle(),
361369
soundName: data.getSound(),
362370
fireDate: Date.parse(data._fireDate),
371+
action: data.getActionIdentifier(),
372+
reply_text: data.getUserText(),
363373
finish: (res) => data.finish(res)
364374
};
365375

@@ -381,6 +391,15 @@ Notifications._transformNotificationObject = function(data, isFromBackground = n
381391
/* void */
382392
}
383393
}
394+
395+
if ( typeof _notification.userInfo === 'string' ) {
396+
try {
397+
_notification.userInfo = JSON.parse(_notification.userInfo);
398+
} catch(e) {
399+
/* void */
400+
}
401+
}
402+
384403

385404
_notification.data = {
386405
...(typeof _notification.userInfo === 'object' ? _notification.userInfo : {}),
@@ -521,11 +540,17 @@ Notifications.getScheduledLocalNotifications = function(callback) {
521540
date: (notif.date ? new Date(notif.date) : null),
522541
number: notif?.badge,
523542
message: notif?.body,
524-
title: notif?.title,
543+
title: notif?.title,
544+
data: notif?.userInfo
525545
})
526546
})
527547
} else if(Platform.OS === 'android') {
528548
mappedNotifications = notifications.map(notif => {
549+
550+
try {
551+
notif.data = JSON.parse(notif.data);
552+
} catch(e) { }
553+
529554
return ({
530555
soundName: notif.soundName,
531556
repeatInterval: notif.repeatInterval,
@@ -534,6 +559,7 @@ Notifications.getScheduledLocalNotifications = function(callback) {
534559
number: notif.number,
535560
message: notif.message,
536561
title: notif.title,
562+
data: notif.data,
537563
})
538564
})
539565
}
@@ -576,4 +602,8 @@ Notifications.deleteChannel = function() {
576602
return this.callNative('deleteChannel', arguments);
577603
};
578604

605+
Notifications.setNotificationCategories = function() {
606+
return this.callNative('setNotificationCategories', arguments);
607+
}
608+
579609
module.exports = Notifications;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-push-notification",
3-
"version": "6.1.3",
3+
"version": "7.0.0",
44
"description": "React Native Local and Remote Notifications",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)