Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Dallas62 committed Aug 3, 2020
2 parents 9c34ed6 + 1f97855 commit f42a581
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ android/src/main/gen

#Debug only
google-services.json

.vscode/
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

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

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

## [Unreleased]

### Breaking changes

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

### Features

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

### Fixed

- (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).
- (Android) `notification.foreground` now return the good value, before the value was `false` most of the time.

## [4.0.0] 2020-07-06

Expand Down
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
React Native Local and Remote Notifications for iOS and Android


## 🎉 Version 4.0.0 is live ! 🎉
## 🎉 Version 5.0.0 is live ! 🎉

Check out for changes in the CHANGELOG:

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

# Supporting the project

Maintaining this project takes time. To help allocate time, you can Buy Me a Coffee :wink:

<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>

## Supported React Native Versions

Expand Down Expand Up @@ -302,13 +307,12 @@ EXAMPLE:
```javascript
PushNotification.localNotification({
/* Android Only Properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
showWhen: true, // (optional) default: true
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
largeIcon: "ic_launcher", // (optional) default: "ic_launcher". Use "" for no large icon.
largeIconUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher". Use "" for default small icon.
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
subText: "This is a subText", // (optional) default: none
bigPictureUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
Expand All @@ -327,18 +331,21 @@ PushNotification.localNotification({
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
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.
onlyAlertOnce: false, //(optional) alert will open only once with sound and notify, default: false


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.

actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true

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

/* iOS and Android properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
title: "My Notification Title", // (optional)
message: "My Notification Message", // (required)
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
playSound: false, // (optional) default: true
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)
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
Expand All @@ -360,6 +367,18 @@ PushNotification.localNotificationSchedule({
});
```

## Get the initial notification

`PushNotification.popInitialNotification(callback)`

EXAMPLE:

```javascript
PushNotification.popInitialNotification((notification) => {
console.log('Initial Notification', notification);
});
```

## Custom sounds

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

## Channel Management (Android)

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`.
To use custom channels, create them at startup and pass the matching `channelId` through to `PushNotification.localNotification`

```javascript
PushNotification.createChannel(
{
channelId: "custom-channel-id", // (required)
channelName: "Custom channel", // (required)
channelDescription: "A custom channel to categorise your custom notifications", // (optional) default: undefined.
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: 4, // (optional) default: 4. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
},
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
);
```

Channels with ids that do not exist are generated on the fly when you pass options to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.

The pattern of `channel_id` is:

Expand Down Expand Up @@ -647,10 +682,6 @@ Works natively in iOS.

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

## Sending Notification Data From Server

Same parameters as `PushNotification.localNotification()`

## Android Only Methods

`PushNotification.subscribeToTopic(topic: string)` Subscribe to a topic (works only with Firebase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ private Bundle getBundleFromIntent(Intent intent) {
public void onNewIntent(Intent intent) {
Bundle bundle = this.getBundleFromIntent(intent);
if (bundle != null) {
bundle.putBoolean("foreground", false);
intent.putExtra("notification", bundle);
mJsDelivery.notifyNotification(bundle);
}
}
Expand Down Expand Up @@ -297,6 +295,18 @@ public void channelExists(String channel_id, Callback callback) {
}
}

@ReactMethod
/**
* Creates a channel if it does not already exist. Returns whether the channel was created.
*/
public void createChannel(ReadableMap channelInfo, Callback callback) {
boolean created = mRNPushNotificationHelper.createChannel(channelInfo);

if(callback != null) {
callback.invoke(created);
}
}

@ReactMethod
/**
* Check if channel is blocked with a given id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class RNPushNotificationAttributes {
private static final String COLOR = "color";
private static final String GROUP = "group";
private static final String GROUP_SUMMARY = "groupSummary";
private static final String USER_INTERACTION = "userInteraction";
private static final String MESSAGE_ID = "messageId";
private static final String PLAY_SOUND = "playSound";
private static final String VIBRATE = "vibrate";
private static final String VIBRATION = "vibration";
Expand All @@ -44,6 +44,7 @@ public class RNPushNotificationAttributes {
private static final String TAG = "tag";
private static final String REPEAT_TYPE = "repeatType";
private static final String REPEAT_TIME = "repeatTime";
private static final String ONLY_ALERT_ONCE = "onlyAlertOnce";
private static final String ONGOING = "ongoing";
private static final String ALLOW_WHILE_IDLE = "allowWhileIdle";
private static final String IGNORE_IN_FOREGROUND = "ignoreInForeground";
Expand All @@ -70,6 +71,7 @@ public class RNPushNotificationAttributes {
private final String color;
private final String group;
private final boolean groupSummary;
private final String messageId;
private final boolean userInteraction;
private final boolean playSound;
private final boolean vibrate;
Expand All @@ -79,6 +81,7 @@ public class RNPushNotificationAttributes {
private final String tag;
private final String repeatType;
private final double repeatTime;
private final boolean onlyAlertOnce;
private final boolean ongoing;
private final boolean allowWhileIdle;
private final boolean ignoreInForeground;
Expand Down Expand Up @@ -106,7 +109,7 @@ public RNPushNotificationAttributes(Bundle bundle) {
color = bundle.getString(COLOR);
group = bundle.getString(GROUP);
groupSummary = bundle.getBoolean(GROUP_SUMMARY);
userInteraction = bundle.getBoolean(USER_INTERACTION);
messageId = bundle.getString(MESSAGE_ID);
playSound = bundle.getBoolean(PLAY_SOUND);
vibrate = bundle.getBoolean(VIBRATE);
vibration = bundle.getDouble(VIBRATION);
Expand All @@ -115,6 +118,7 @@ public RNPushNotificationAttributes(Bundle bundle) {
tag = bundle.getString(TAG);
repeatType = bundle.getString(REPEAT_TYPE);
repeatTime = bundle.getDouble(REPEAT_TIME);
onlyAlertOnce = bundle.getBoolean(ONLY_ALERT_ONCE);
ongoing = bundle.getBoolean(ONGOING);
allowWhileIdle = bundle.getBoolean(ALLOW_WHILE_IDLE);
ignoreInForeground = bundle.getBoolean(IGNORE_IN_FOREGROUND);
Expand Down Expand Up @@ -144,7 +148,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
color = jsonObject.has(COLOR) ? jsonObject.getString(COLOR) : null;
group = jsonObject.has(GROUP) ? jsonObject.getString(GROUP) : null;
groupSummary = jsonObject.has(GROUP_SUMMARY) ? jsonObject.getBoolean(GROUP_SUMMARY) : false;
userInteraction = jsonObject.has(USER_INTERACTION) ? jsonObject.getBoolean(USER_INTERACTION) : false;
messageId = jsonObject.has(MESSAGE_ID) ? jsonObject.getString(MESSAGE_ID) : null;
playSound = jsonObject.has(PLAY_SOUND) ? jsonObject.getBoolean(PLAY_SOUND) : true;
vibrate = jsonObject.has(VIBRATE) ? jsonObject.getBoolean(VIBRATE) : true;
vibration = jsonObject.has(VIBRATION) ? jsonObject.getDouble(VIBRATION) : 1000;
Expand All @@ -153,6 +157,7 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
tag = jsonObject.has(TAG) ? jsonObject.getString(TAG) : null;
repeatType = jsonObject.has(REPEAT_TYPE) ? jsonObject.getString(REPEAT_TYPE) : null;
repeatTime = jsonObject.has(REPEAT_TIME) ? jsonObject.getDouble(REPEAT_TIME) : 0.0;
onlyAlertOnce = jsonObject.has(ONLY_ALERT_ONCE) ? jsonObject.getBoolean(ONLY_ALERT_ONCE) : false;
ongoing = jsonObject.has(ONGOING) ? jsonObject.getBoolean(ONGOING) : false;
allowWhileIdle = jsonObject.has(ALLOW_WHILE_IDLE) ? jsonObject.getBoolean(ALLOW_WHILE_IDLE) : false;
ignoreInForeground = jsonObject.has(IGNORE_IN_FOREGROUND) ? jsonObject.getBoolean(IGNORE_IN_FOREGROUND) : false;
Expand Down Expand Up @@ -239,7 +244,7 @@ public Bundle toBundle() {
bundle.putString(COLOR, color);
bundle.putString(GROUP, group);
bundle.putBoolean(GROUP_SUMMARY, groupSummary);
bundle.putBoolean(USER_INTERACTION, userInteraction);
bundle.putString(MESSAGE_ID, messageId);
bundle.putBoolean(PLAY_SOUND, playSound);
bundle.putBoolean(VIBRATE, vibrate);
bundle.putDouble(VIBRATION, vibration);
Expand All @@ -248,6 +253,7 @@ public Bundle toBundle() {
bundle.putString(TAG, tag);
bundle.putString(REPEAT_TYPE, repeatType);
bundle.putDouble(REPEAT_TIME, repeatTime);
bundle.putBoolean(ONLY_ALERT_ONCE, onlyAlertOnce);
bundle.putBoolean(ONGOING, ongoing);
bundle.putBoolean(ALLOW_WHILE_IDLE, allowWhileIdle);
bundle.putBoolean(IGNORE_IN_FOREGROUND, ignoreInForeground);
Expand Down Expand Up @@ -279,7 +285,7 @@ public JSONObject toJson() {
jsonObject.put(COLOR, color);
jsonObject.put(GROUP, group);
jsonObject.put(GROUP_SUMMARY, groupSummary);
jsonObject.put(USER_INTERACTION, userInteraction);
jsonObject.put(MESSAGE_ID, messageId);
jsonObject.put(PLAY_SOUND, playSound);
jsonObject.put(VIBRATE, vibrate);
jsonObject.put(VIBRATION, vibration);
Expand All @@ -288,6 +294,7 @@ public JSONObject toJson() {
jsonObject.put(TAG, tag);
jsonObject.put(REPEAT_TYPE, repeatType);
jsonObject.put(REPEAT_TIME, repeatTime);
jsonObject.put(ONLY_ALERT_ONCE, onlyAlertOnce);
jsonObject.put(ONGOING, ongoing);
jsonObject.put(ALLOW_WHILE_IDLE, allowWhileIdle);
jsonObject.put(IGNORE_IN_FOREGROUND, ignoreInForeground);
Expand Down Expand Up @@ -325,6 +332,7 @@ public String toString() {
", color='" + color + '\'' +
", group='" + group + '\'' +
", groupSummary='" + groupSummary + '\'' +
", messageId='" + messageId + '\'' +
", userInteraction=" + userInteraction +
", playSound=" + playSound +
", vibrate=" + vibrate +
Expand All @@ -334,6 +342,7 @@ public String toString() {
", tag='" + tag + '\'' +
", repeatType='" + repeatType + '\'' +
", repeatTime=" + repeatTime +
", onlyAlertOnce=" + onlyAlertOnce +
", ongoing=" + ongoing +
", allowWhileIdle=" + allowWhileIdle +
", ignoreInForeground=" + ignoreInForeground +
Expand Down
Loading

0 comments on commit f42a581

Please sign in to comment.