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

Commit ee6a62e

Browse files
committed
Implement features for #1588.
1 parent c391403 commit ee6a62e

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
1111
### Features
1212

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

1516
### Fixed
1617

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,12 @@ PushNotification.localNotification({
329329
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)
330330
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
331331
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.
332-
onlyAlertOnce: false, //(optional) alert will open only once with sound and notify, default: false
333-
332+
onlyAlertOnce: false, // (optional) alert will open only once with sound and notify, default: false
333+
334+
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.
335+
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.
336+
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null
337+
334338
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.
335339

336340
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ 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 WHEN = "when";
48+
private static final String USES_CHRONOMETER = "usesChronometer";
49+
private static final String TIMEOUT_AFTER = "timeoutAfter";
4750
private static final String ONLY_ALERT_ONCE = "onlyAlertOnce";
4851
private static final String ONGOING = "ongoing";
4952
private static final String ALLOW_WHILE_IDLE = "allowWhileIdle";
@@ -80,6 +83,9 @@ public class RNPushNotificationAttributes {
8083
private final String tag;
8184
private final String repeatType;
8285
private final double repeatTime;
86+
private final double when;
87+
private final boolean usesChronometer;
88+
private final double timeoutAfter;
8389
private final boolean onlyAlertOnce;
8490
private final boolean ongoing;
8591
private final boolean allowWhileIdle;
@@ -117,6 +123,9 @@ public RNPushNotificationAttributes(Bundle bundle) {
117123
tag = bundle.getString(TAG);
118124
repeatType = bundle.getString(REPEAT_TYPE);
119125
repeatTime = bundle.getDouble(REPEAT_TIME);
126+
when = bundle.getDouble(WHEN);
127+
usesChronometer = bundle.getBoolean(USES_CHRONOMETER);
128+
timeoutAfter = bundle.getDouble(TIMEOUT_AFTER);
120129
onlyAlertOnce = bundle.getBoolean(ONLY_ALERT_ONCE);
121130
ongoing = bundle.getBoolean(ONGOING);
122131
allowWhileIdle = bundle.getBoolean(ALLOW_WHILE_IDLE);
@@ -156,6 +165,9 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
156165
tag = jsonObject.has(TAG) ? jsonObject.getString(TAG) : null;
157166
repeatType = jsonObject.has(REPEAT_TYPE) ? jsonObject.getString(REPEAT_TYPE) : null;
158167
repeatTime = jsonObject.has(REPEAT_TIME) ? jsonObject.getDouble(REPEAT_TIME) : 0.0;
168+
when = jsonObject.has(WHEN) ? jsonObject.getDouble(WHEN) : null;
169+
usesChronometer = jsonObject.has(USES_CHRONOMETER) ? jsonObject.getBoolean(USES_CHRONOMETER) : false;
170+
timeoutAfter = jsonObject.has(TIMEOUT_AFTER) ? jsonObject.getDouble(TIMEOUT_AFTER) : null;
159171
onlyAlertOnce = jsonObject.has(ONLY_ALERT_ONCE) ? jsonObject.getBoolean(ONLY_ALERT_ONCE) : false;
160172
ongoing = jsonObject.has(ONGOING) ? jsonObject.getBoolean(ONGOING) : false;
161173
allowWhileIdle = jsonObject.has(ALLOW_WHILE_IDLE) ? jsonObject.getBoolean(ALLOW_WHILE_IDLE) : false;
@@ -252,6 +264,9 @@ public Bundle toBundle() {
252264
bundle.putString(TAG, tag);
253265
bundle.putString(REPEAT_TYPE, repeatType);
254266
bundle.putDouble(REPEAT_TIME, repeatTime);
267+
bundle.putDouble(WHEN, when);
268+
bundle.putBoolean(USES_CHRONOMETER, usesChronometer);
269+
bundle.putDouble(TIMEOUT_AFTER, timeoutAfter);
255270
bundle.putBoolean(ONLY_ALERT_ONCE, onlyAlertOnce);
256271
bundle.putBoolean(ONGOING, ongoing);
257272
bundle.putBoolean(ALLOW_WHILE_IDLE, allowWhileIdle);
@@ -293,6 +308,9 @@ public JSONObject toJson() {
293308
jsonObject.put(TAG, tag);
294309
jsonObject.put(REPEAT_TYPE, repeatType);
295310
jsonObject.put(REPEAT_TIME, repeatTime);
311+
jsonObject.put(WHEN, when);
312+
jsonObject.put(USES_CHRONOMETER, usesChronometer);
313+
jsonObject.put(TIMEOUT_AFTER, timeoutAfter);
296314
jsonObject.put(ONLY_ALERT_ONCE, onlyAlertOnce);
297315
jsonObject.put(ONGOING, ongoing);
298316
jsonObject.put(ALLOW_WHILE_IDLE, allowWhileIdle);
@@ -340,6 +358,9 @@ public String toString() {
340358
", tag='" + tag + '\'' +
341359
", repeatType='" + repeatType + '\'' +
342360
", repeatTime=" + repeatTime +
361+
", when=" + when +
362+
", usesChronometer=" + usesChronometer +
363+
", timeoutAfter=" + timeoutAfter +
343364
", onlyAlertOnce=" + onlyAlertOnce +
344365
", ongoing=" + ongoing +
345366
", allowWhileIdle=" + allowWhileIdle +

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,22 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
498498
if (shortcutId != null) {
499499
notification.setShortcutId(shortcutId);
500500
}
501+
502+
Long timeoutAfter = (long) bundle.getDouble("timeoutAfter");
503+
504+
if (timeoutAfter != null) {
505+
notification.setTimeoutAfter(timeoutAfter);
506+
}
507+
}
508+
509+
Long when = (long) bundle.getDouble("when");
510+
511+
if (when != null) {
512+
notification.setWhen(when);
501513
}
502514

515+
notification.setUsesChronometer(bundle.getBoolean("usesChronometer", false));
516+
503517
// Override channel_id if there is one provided
504518
String customChannelId = bundle.getString("channelId");
505519

example/NotifService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ export default class NotifService {
5555
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
5656
tag: 'some_tag', // (optional) add tag to message
5757
group: 'group', // (optional) add group to message
58+
groupSummary: false, // (optional) set this notification to be the group summary for a group of notifications, default: false
5859
ongoing: false, // (optional) set whether this is an "ongoing" notification
5960
actions: ['Yes', 'No'], // (Android only) See the doc for notification actions to know more
6061
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
6162

63+
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.
64+
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.
65+
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null
66+
6267
/* iOS only properties */
6368
alertAction: 'view', // (optional) default: view
6469
category: '', // (optional) default: empty string
@@ -91,10 +96,15 @@ export default class NotifService {
9196
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
9297
tag: 'some_tag', // (optional) add tag to message
9398
group: 'group', // (optional) add group to message
99+
groupSummary: false, // (optional) set this notification to be the group summary for a group of notifications, default: false
94100
ongoing: false, // (optional) set whether this is an "ongoing" notification
95101
actions: ['Yes', 'No'], // (Android only) See the doc for notification actions to know more
96102
invokeApp: false, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
97103

104+
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.
105+
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.
106+
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null
107+
98108
/* iOS only properties */
99109
alertAction: 'view', // (optional) default: view
100110
category: '', // (optional) default: empty string

0 commit comments

Comments
 (0)