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

Commit

Permalink
Implement features for #1588.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dallas62 committed Aug 16, 2020
1 parent c391403 commit ee6a62e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
### Features

- (Android) Add support for specifying a delegate FirebaseMessagingService [#1589](https://github.com/zo0r/react-native-push-notification/pull/1589)
- (Android) Add support of `when`, `usesChronometer` and `timeoutAfter`.

### Fixed

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,12 @@ PushNotification.localNotification({
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
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

onlyAlertOnce: false, // (optional) alert will open only once with sound and notify, default: false

when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false.
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ 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 WHEN = "when";
private static final String USES_CHRONOMETER = "usesChronometer";
private static final String TIMEOUT_AFTER = "timeoutAfter";
private static final String ONLY_ALERT_ONCE = "onlyAlertOnce";
private static final String ONGOING = "ongoing";
private static final String ALLOW_WHILE_IDLE = "allowWhileIdle";
Expand Down Expand Up @@ -80,6 +83,9 @@ public class RNPushNotificationAttributes {
private final String tag;
private final String repeatType;
private final double repeatTime;
private final double when;
private final boolean usesChronometer;
private final double timeoutAfter;
private final boolean onlyAlertOnce;
private final boolean ongoing;
private final boolean allowWhileIdle;
Expand Down Expand Up @@ -117,6 +123,9 @@ public RNPushNotificationAttributes(Bundle bundle) {
tag = bundle.getString(TAG);
repeatType = bundle.getString(REPEAT_TYPE);
repeatTime = bundle.getDouble(REPEAT_TIME);
when = bundle.getDouble(WHEN);
usesChronometer = bundle.getBoolean(USES_CHRONOMETER);
timeoutAfter = bundle.getDouble(TIMEOUT_AFTER);
onlyAlertOnce = bundle.getBoolean(ONLY_ALERT_ONCE);
ongoing = bundle.getBoolean(ONGOING);
allowWhileIdle = bundle.getBoolean(ALLOW_WHILE_IDLE);
Expand Down Expand Up @@ -156,6 +165,9 @@ 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;
when = jsonObject.has(WHEN) ? jsonObject.getDouble(WHEN) : null;
usesChronometer = jsonObject.has(USES_CHRONOMETER) ? jsonObject.getBoolean(USES_CHRONOMETER) : false;
timeoutAfter = jsonObject.has(TIMEOUT_AFTER) ? jsonObject.getDouble(TIMEOUT_AFTER) : null;
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;
Expand Down Expand Up @@ -252,6 +264,9 @@ public Bundle toBundle() {
bundle.putString(TAG, tag);
bundle.putString(REPEAT_TYPE, repeatType);
bundle.putDouble(REPEAT_TIME, repeatTime);
bundle.putDouble(WHEN, when);
bundle.putBoolean(USES_CHRONOMETER, usesChronometer);
bundle.putDouble(TIMEOUT_AFTER, timeoutAfter);
bundle.putBoolean(ONLY_ALERT_ONCE, onlyAlertOnce);
bundle.putBoolean(ONGOING, ongoing);
bundle.putBoolean(ALLOW_WHILE_IDLE, allowWhileIdle);
Expand Down Expand Up @@ -293,6 +308,9 @@ public JSONObject toJson() {
jsonObject.put(TAG, tag);
jsonObject.put(REPEAT_TYPE, repeatType);
jsonObject.put(REPEAT_TIME, repeatTime);
jsonObject.put(WHEN, when);
jsonObject.put(USES_CHRONOMETER, usesChronometer);
jsonObject.put(TIMEOUT_AFTER, timeoutAfter);
jsonObject.put(ONLY_ALERT_ONCE, onlyAlertOnce);
jsonObject.put(ONGOING, ongoing);
jsonObject.put(ALLOW_WHILE_IDLE, allowWhileIdle);
Expand Down Expand Up @@ -340,6 +358,9 @@ public String toString() {
", tag='" + tag + '\'' +
", repeatType='" + repeatType + '\'' +
", repeatTime=" + repeatTime +
", when=" + when +
", usesChronometer=" + usesChronometer +
", timeoutAfter=" + timeoutAfter +
", onlyAlertOnce=" + onlyAlertOnce +
", ongoing=" + ongoing +
", allowWhileIdle=" + allowWhileIdle +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,22 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
if (shortcutId != null) {
notification.setShortcutId(shortcutId);
}

Long timeoutAfter = (long) bundle.getDouble("timeoutAfter");

if (timeoutAfter != null) {
notification.setTimeoutAfter(timeoutAfter);
}
}

Long when = (long) bundle.getDouble("when");

if (when != null) {
notification.setWhen(when);
}

notification.setUsesChronometer(bundle.getBoolean("usesChronometer", false));

// Override channel_id if there is one provided
String customChannelId = bundle.getString("channelId");

Expand Down
10 changes: 10 additions & 0 deletions example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ export default class NotifService {
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: 'group', // (optional) add group to message
groupSummary: false, // (optional) set this notification to be the group summary for a group of notifications, default: false
ongoing: false, // (optional) set whether this is an "ongoing" notification
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

when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false.
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null

/* iOS only properties */
alertAction: 'view', // (optional) default: view
category: '', // (optional) default: empty string
Expand Down Expand Up @@ -91,10 +96,15 @@ export default class NotifService {
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: 'group', // (optional) add group to message
groupSummary: false, // (optional) set this notification to be the group summary for a group of notifications, default: false
ongoing: false, // (optional) set whether this is an "ongoing" notification
actions: ['Yes', 'No'], // (Android only) See the doc for notification actions to know more
invokeApp: false, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true

when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false.
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null

/* iOS only properties */
alertAction: 'view', // (optional) default: view
category: '', // (optional) default: empty string
Expand Down

0 comments on commit ee6a62e

Please sign in to comment.