Closed A320Peter closed 3 years ago
I did some experiment in a short trial and I have no idea why, but in the first 0-2.4 seconds it's possible to dismiss the alert however later it is not. I tested and it is receiving the onTapGesture
event and the isPresenting
changes to false
but the alert stays on the screen no matter what regardless isPresenting
false or true. If I tap or set isPresenting
withing 2.4 seconds it works as expected.
In a new project I can not reproduce this behaviour so I am looking deeper into it.
It seems to works great on my side. Can you please submit the ObservableObject
you're using?
I think that is where the problem.
Also, if RM
is an ObservableObject
, so the implementation should look like this:
Read this article about how to implement Alert Toast with ObservableObject
correctly (the Bonus section):
How to toast an alert in SwiftUI
//Notice the dollar sign
.toast(isPresenting: $RM.pendingNotifications, duration: 3.0) {
AlertToast(displayMode: .hud, type: .systemImage("exclamationmark.triangle.fill", Color.orange), title: "alert alert alert")
}
Thanks I have it now. Nothing is wrong with your code. In my case it's a complicated project and the observable object @Published
variable was indirectly connected to a custom property wrapper. For some reason this value is not updating if the new value source is outside of the object.
I could reproduce it in a more simple way with an @AppStorage
wrapper in iOS14. I don't have much experience with @AppStorage
so probably it's a normal behaviour but modifying this from outside of the observable object also preventing the alert to disappear. Probably the change is not pushed down the hierarchy.
Thanks again for this framework, it's awesome.
Glad you found a solution 😊
This is a really cool framework but I am having problem dismissing the alert if I set duration greater than 2.0. Default setting works as expected.
This works perfectly (view diasappears after 2 seconds):
The code below does not work. With any duration above 2.0 the view appears and never disappears. It stays on top of the screen. Tap to dismiss also does not work. I also cannot influence anything with tapToDismiss:
RM is an observable object exposed to the environment and pendingNotifications is @Published variable.