Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss does not work when using .loading alert #16

Closed
bzbislawski opened this issue Sep 3, 2021 · 3 comments
Closed

Dismiss does not work when using .loading alert #16

bzbislawski opened this issue Sep 3, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@bzbislawski
Copy link

Describe the bug
I expect to display loading alert. Once Published variable changes to different value then I'd expect new alert to display only 2 seconds, not infinite. Also tap to dismiss does not work in this case

Expected behavior
.toast(isPresenting: $showToast) { if viewModel.sendMessageResponse == .successfullySent { return AlertToast(type: .complete(.green), title: "Message Sent!", custom: .custom(backgroundColor: Color.customYellow)) } else if viewModel.sendMessageResponse == .errornousResponse { return AlertToast(type: .error(.red), title: "Unable to send message!", custom: .custom(backgroundColor: Color.customYellow)) } else { return AlertToast(displayMode: .alert, type: .loading, custom: .custom(backgroundColor: Color.customYellow)) }

Steps

  1. Change showToast to true -> this displays loading alert
  2. Waiting for async call to update sendMessageResponse to .successfullySent or .errornousResponse
  3. Alert green or red is displayed infinitely and it is impossible to to tap to dismiss success/error alert.
@bzbislawski bzbislawski added the bug Something isn't working label Sep 3, 2021
@elai950
Copy link
Owner

elai950 commented Sep 5, 2021

You should create an @Published var alertToast: AlertToast object in ObservableObject instead of using if else.

Read the bonus section here

Then just add functions to set the alertToast var.

class AlertViewModel: ObservableObject{
    
    /// ... properties

  func showComplete(){
     alertToast = AlertToast(type: .complete(.green), title: "Message Sent!", custom: .custom(backgroundColor: Color.customYellow))
  }

}

When your async call update (for example) the sendMessageResponse just set call showComplete() func.

Also,
The loading alert toast disables the tapToDismiss and sets the duration to 0 for his view modifier, so I recommend creating 2 different .toast view modifiers (you can add multiple toast view modifiers on the same view).
One for the loading and another one for Complete & Error.

@bzbislawski
Copy link
Author

One for the loading and another one for Complete & Error.

Yes, this is what I did.
I also hoped that maybe completion modifier can return another alert but it is not a case. Thanks

@elai950
Copy link
Owner

elai950 commented Sep 9, 2021

Just add showComplete/Error.toggle() in the completion handler.

I'm closing the issue, if you'll need any more help please reopen it.

@elai950 elai950 closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants