A similar question in the UIKit: How to dismiss UIAlertController when tap outside the UIAlertController?
I have a basic alert with a few buttons (cancel/delete style). I'd like to "dismiss" the alert by tapping outside of it, similarly to what would "cancel" button do:
struct ContentView: View {
@State private var showingAlert = false
var body: some View {
Button("Show Alert") {
showingAlert = true
}
.alert("Important message", isPresented: $showingAlert) {
Button("First") { }
Button("Second") { }
Button("Third") { }
}
}
}
I tried adding onTapGesture
handler, but it didn't help.