Skip to content

fix(local-notifications): Notifications are not generated when using defaults#602

Merged
NathanWalker merged 13 commits intoNativeScript:mainfrom
CatchABus:fix-local-notifications
Oct 13, 2024
Merged

fix(local-notifications): Notifications are not generated when using defaults#602
NathanWalker merged 13 commits intoNativeScript:mainfrom
CatchABus:fix-local-notifications

Conversation

@CatchABus
Copy link
Contributor

This PR is an attempt to fix #595 along with some cleanup.

@CatchABus CatchABus marked this pull request as draft October 11, 2024 18:54
for (const s of scheduleOptions) {
const entry = LocalNotificationsImpl.createScheduleEntry(s);
// Some properties should not be inherited by options
const nativeOptions: ScheduleNativeOptions = { ...entry, color: undefined, notificationLed: undefined };
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the idea of this extend? Won't this always nullify the properties that are sent by users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not at all. The nativeOptions object is meant for being sent to the native side as a json string.
In line 223, we mark color and notificationLed as undefined to:

  • Prevent them from being read from native lib in case they're not set below (because they're set below)
  • Correct type warnings

registerNotification(entry.id, content, trigger, scheduledIds);

if (interval && entry.displayImmediately) {
const id = LocalNotificationsImpl.generateNotificationID();
Copy link
Contributor

Choose a reason for hiding this comment

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

Unlike the old logic, won't this generate a new ID. What will happen if I decide to cancel the ID of the original request? To me the old logic would cancel both the immediately scheduled one and the other one that was scheduled with interval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it worked for you that way. Perhaps, you're confused.
Even now, immediate notifications have their own unique ID.
See:
https://github.com/NativeScript/plugins/blob/main/packages/local-notifications/index.android.ts#L241
https://github.com/NativeScript/plugins/blob/main/packages/local-notifications/index.ios.ts#L151

@NathanWalker NathanWalker marked this pull request as ready for review October 12, 2024 18:30
@NathanWalker NathanWalker merged commit 2abfa84 into NativeScript:main Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[@nativescript/local-notifications] No notifications are displayed when relying on default option values

3 participants