ToastUI
ToastUI copied to clipboard
Is there a function to hide the toast by clicking on the outside now?
I want click outside to dismiss toast
Hi @coder-free,
I don't have any plan to add this feature at the moment. ToastUI is implemented by presenting an internal UIWindow
consists of your provided SwiftUI view entirely. Therefore, it's a little bit tricky to implement this directly in the internal UIWindow
.
Please feel free to open a PR if you have an example implementation.
Hi @coder-free,
Technically, you can implement this in your SwiftUI view by handling tap gesture that occurred outside of your view and then dismiss it.
struct TapOutsideToDismissToastExample: View {
@State private var presentingToast = false
var body: some View {
Button {
presentingToast = true
} label: {
Text("Tap me")
}
.toast(isPresented: $presentingToast) {
ToastView("Tap anywhere to dismiss")
.toastViewStyle(.information)
.background(
Color.clear.contentShape(Rectangle())
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onTapGesture {
presentingToast = false
}
)
}
}
}
Please don't hesitate to reopen this issue if you have any further questions.