fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.2k stars 1.4k forks source link

Notification actions/callbacks #4953

Open hkparker opened 5 months ago

hkparker commented 5 months ago

Checklist

Is your feature request related to a problem?

Notifications right now just display a string, and on mobile you don't appear to be able to click them to enter the app. On many mobile applications, clicking notifications not only opens the app, but opens it to the context / feature of the app relevant to the notification (think how clicking the notification of a chat app takes you to the specific conversation thread that created the notification).

I'd like to be able to send notifications with Fyne that, when the platform allows for it, let the user click the notification and enter the app with context.

Is it possible to construct a solution with the existing API?

Not that I'm aware of

Describe the solution you'd like to see.

notification := fyne.NewNotification("Title", "Content", func() {
    // This notification was clicked, now I can take some action and/or display the relevant container in the app
})
Jacalz commented 5 months ago

This is a great addition. However, do keep in mind that modifying the NewAnimation function when implementing this would be a breaking change. It would have to be part of the struct and maybe in a separate fyne.NewAnimationWithCallback function (or similar).

andydotxyz commented 5 months ago

I'm not sure it can be done with functions, though it would be nice if that was possible. I think the lowest common denominator to notifications would be entering the app through a deep link... but this task needs real investigation to learn what is possible before we put an API on it.

hkparker commented 4 months ago

I'd imagine something like this for the API side of that

myDeepLink := url.Url{} // url that should be used to call into the app when the notification is clicked
notification := fyne.NewNotificationWithDeepLink("Title", "Content", myDeepLink)
myapp.SetDeepLinkHandler(func(deepLink url.URL) {
    // match the URL to a rule and do anything / display anything as needed
})

With this scheme the developer gets to provide their own function for matching any deep link, which is very flexible