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

Detecting a tap on the banner #9

Closed
helloniklas opened this issue Jun 18, 2021 · 4 comments
Closed

Detecting a tap on the banner #9

helloniklas opened this issue Jun 18, 2021 · 4 comments

Comments

@helloniklas
Copy link

Is there an easy way to detect a tap on the banner in order to take an action if it was tapped or not.

@elai950
Copy link
Owner

elai950 commented Jun 18, 2021

You can use the completion handler to take an action:

.toast(isPresenting: $showAlert, duration: 2, tapToDismiss: true, alert: {
   //AlertToast Goes Here
}, completion: { dismissed in
   //Completion block after dismiss (returns true)
})

Hope this answers your question.

@helloniklas
Copy link
Author

I tried that, but it's always called with true. So I can't differentiate between user tapping on to dismiss, or it just being auto dismissed after 2 seconds. The same complexion handler is called on both occasions.

@elai950
Copy link
Owner

elai950 commented Jun 18, 2021

I've now added a new handler onTap that you can use.

.toast(isPresenting: $showAlert, duration: 2, tapToDismiss: true, alert: {
   //AlertToast Goes Here
}, onTap: {
 //On tap would call either `tapToDismiss` is false/true
 //If tapToDismiss is true, this action would call and then dismiss the alert
}, completion: {
   //Completion block after dismiss WITHOUT escaping variables
})

Don't forget to set duration to 0 if you don't want the alert to be auto dismissed.
If you don't get the update in few minutes, try adding with SPM from the master branch.

In the next update, all add this function as a function to AlertToast type.

Would look like this:

AlertToast(type: .regular, title: "Next Update")
.onTap{
 //Actions goes here
}

Watch the repo if you would like to be notified.

@helloniklas
Copy link
Author

Amazing that’s great. Thanks.

@elai950 elai950 closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants