Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
map scheduled local notifications to united return object for both pl…
…atforms
  • Loading branch information
lukebars committed Jun 8, 2020
commit b62b27b16de43a76e8dc298231b8db0dfb380123
38 changes: 36 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,42 @@ Notifications.getDeliveredNotifications = function() {
return this.callNative('getDeliveredNotifications', arguments);
}

Notifications.getScheduledLocalNotifications = function() {
return this.callNative('getScheduledLocalNotifications', arguments);
Notifications.getScheduledLocalNotifications = function(callback) {
const mapNotifications = (notifications) => {
let mappedNotifications = [];
if(notifications?.length > 0) {
if(Platform.OS === 'ios'){
mappedNotifications = notifications.map(notif => {
return ({
soundName: notif.soundName,
repeatInterval: notif.repeatInterval,
remote: notif.remote,
id: notif.userInfo?.id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about this line,
I totally agree iOS should have the notification ID, but by default, userInfo is set to {}.
Not sure if we need to set a default value on userInfo (notificationId ?) or let this field empty when the developer doesn't set it in userInfo...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why it's optional chained here. It would result in undefined if it is not set. Currently we're using userInfo.id for cancelling notifications by id, so it makes sense to me.

Copy link
Contributor Author

@lukebars lukebars Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But setting the id as default when scheduling the notification would be an awesome feature IMHO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into it, thanks for the PR !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added the commit here:
6bcc2a9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! 🙏

date: notif.fireDate,
number: notif?.applicationIconBadgeNumber,
message: notif?.alertBody,
title: notif?.alertTitle,
})
})
} else if(Platform.OS === 'android') {
mappedNotifications = notifications.map(notif => {
return ({
soundName: notif.soundName,
repeatInterval: notif.repeatInterval,
remote: notif.remote,
id: notif.id,
date: notif.date,
number: notif.number,
message: notif.message,
title: notif.title,
})
})
}
}
callback(mappedNotifications);
}

return this.callNative('getScheduledLocalNotifications', [mapNotifications]);
}

Notifications.removeDeliveredNotifications = function() {
Expand Down