JDStatusBarNotification icon indicating copy to clipboard operation
JDStatusBarNotification copied to clipboard

Tap to dismiss on SwiftUI

Open metallica1375 opened this issue 1 year ago • 5 comments

hey, thanks for your awesome library, how can I dismiss the toast or notification in swiftUI form?

metallica1375 avatar Jul 14 '24 08:07 metallica1375

Dismissing a notification

NotificationPresenter.shared.dismiss()

// with completion
NotificationPresenter.shared.dismiss(after: 0.5) { presenter in
   // ...
}

calimarkus avatar Jul 14 '24 19:07 calimarkus

Thanks for the hint, but when I call it, it won't work, e.g. in onTagGesture{} in my SwiftUI view component. although I added the onTapDismiss functionality in my fork using UITapGestureRecognizer, but I wanted to check if it can be done directly or not.

metallica1375 avatar Jul 15 '24 16:07 metallica1375

Ah you want to handle custom user interaction? See this sample code you need to disable style.canTapToHold:

https://github.com/calimarkus/JDStatusBarNotification/blob/ffde0bab9fd0b47e426e696b5fe53deefc781452/ExampleProject/ExamplesScreen.swift#L268-L274

calimarkus avatar Jul 15 '24 17:07 calimarkus

No no, I just want to simply dismiss the notification when the user taps anywhere on it

metallica1375 avatar Jul 15 '24 23:07 metallica1375

Yep, for that you need the above. Then you can use swift gesture handling as usual.

By default a user can only swipe to dismiss.

calimarkus avatar Jul 16 '24 07:07 calimarkus