.alert(isPresented:$showingAlert) {
Alert(
title: Text("Are you sure you want to delete this?"),
message: Text("There is no undo"),
primaryButton: .destructive(Text("Delete")) {
//(using showingAlert = false doesn't help.)
//(leaving this section empty doesn't help as well so any code written here is unrelated.)
unrelatedCode()
},
secondaryButton: .cancel()
)
}
Why does this code result in alert coming back to screen no matter which button I press on it? Here's a vid for easier understanding: https://i.stack.imgur.com/qSe9r.jpg
Edit: Seems like a bug on swiftui's side I guess. Guess I'll work around it.
Edit 2: Everything that could be related to the issue:
struct EditProcessView: View {
@State var problem:Bool = false
@State var showingAlert = false
@State var text = ""
var body: some View {
Form{
//2 unrelated pickers.
//Unrelated textfield
Button(“Delete”){
showingAlert = true //Are you sure you want to delete this? Button.
}
}
.frame(minWidth: 200, idealWidth: 200)
.alert(isPresented: $problem) {Alert.init(title: Text(“Fill the textfield with a number.“))}
.alert(isPresented:$showingAlert) {
Alert(
title: Text("Are you sure you want to delete this?"),
message: Text("There is no undo."),
primaryButton: .destructive(Text("Delete")) {
//Unrelated code.
},
secondaryButton: .cancel()
)
}
}