calimarkus / JDStatusBarNotification

Highly customizable & feature rich notifications. Interactive dismiss. Custom Views. SwiftUI. Tap-to-hold. Progress. Written in Swift, compatible for ObjC!
http://calimarkus.github.io/JDStatusBarNotification/documentation/jdstatusbarnotification
MIT License
4.19k stars 556 forks source link

Tap to dismiss on SwiftUI #141

Open metallica1375 opened 2 months ago

metallica1375 commented 2 months ago

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

calimarkus commented 2 months ago

Dismissing a notification

NotificationPresenter.shared.dismiss()

// with completion
NotificationPresenter.shared.dismiss(after: 0.5) { presenter in
   // ...
}
metallica1375 commented 1 month ago

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.

calimarkus commented 1 month ago

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

metallica1375 commented 1 month ago

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

calimarkus commented 1 month ago

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.