NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
190 stars 107 forks source link

[@nativescript/local-notifications] schedule method not intuitive #130

Open vallemar opened 3 years ago

vallemar commented 3 years ago

I have gone to use this plugin for the first time today, when I saw the schedule method I thought that only scheduled notifications can be made and when I have not even seen a .showNotification or something similar I have come to think that the plugin was to manage scheduled tasks. It doesn't seem intuitive to me. Wouldn't it be better to just leave the sceduled for true scheduled and a method that is more descriptive that is to display a notification? I would like to help but I don't see how to contribute to the repo.

shiv19 commented 3 years ago

if you want to call it as "showNotification" and display a notification immediately, you could simple write a wrapper function around it in your own codebase, which takes the notification content and then calls the schedule method passing "new Date()" to the at param,

something like

showNotification({ id, title, body, channel }) {
  // you could add some field validations here

  // Then call the schedule method
  LocalNotifications.schedule([
    {
        id,
        title,
        body,
        badge: 1,
        channel,
        at: new Date(), // now
    },
]).then(
    (scheduledIds) => {
        console.log('Notification id(s) scheduled: ' + JSON.stringify(scheduledIds));
    },
    (error) => {
        console.log('scheduling error: ' + error);
    }
);

}

But with that being said, you can already do that with the schedule method. In my opinion, showing a notification should be treated as an async task anyways.

Hope that helps :)

The readme file here https://github.com/NativeScript/plugins#readme

Has information on how to build this project, you can use that to contribute :)

vallemar commented 3 years ago

@shiv19 First of all, thank you very much for your time and response. But I don't mean that I want to wrap this in a showNotification method for me. What I mean is that I think it would be good to change or add a method similar to showNotification in the plugin. At the compression level, it is much clearer for the arriving programmer than a schedule method,schedule denotes a task and is not clear, most developers will just want to show a notification (I think). I think that schedule does a lot of things, I think that simplifying the methods and doing specific things is cleaner and clearer.

In another place, to contribute to the project I think that all the nativescript repositories should have a format: in the Nativescript repository there is a section: Contribute, I think it would be good to unify all the repos and unify all the title of documentation sections of contributing with the title, for example: Contribute.

PD: this issue is just a recommendation under my thinking and I think it could help people who use the plugin and want to contribute

Erudition commented 2 years ago

All local notifications get scheduled. Some should be delivered right now, and some should be delivered at some other time.

If your use case has not come across a need for notifications any other time than immediately, I can see why you might think the API should revolve around that use case - however, in my use case (a planner), the minority of notifications are scheduled for now, and most of them are scheduled for other, specific times. If it doesn't need to be later, you can simply leave the at time empty.

If you're familiar with the command line on posix/gnu systems, you can use the shutdown command to schedule shutdown of the system at some time. If you want it to happen immediately, you specify shutdown now. Maybe think of this kind of like that.