I trying to display an alert after dismiss the sheet. But when I update the @Binding in the sheet, the alert in home page didn't appear. I don't know what's the problem now. Anyone can explain to me? Is it the problem of using @Binding? If the method/logic of doing this is wrong, what method should I use?
struct ContentView: View {
@State private var showSheet = false
@State var showAlert = false
var body: some View {
VStack {
Text("sheet")
.onTapGesture(perform: {
self.showSheet.toggle()
})
}
.sheet(isPresented: $showSheet) {
AddView(showAlert: self.$showAlert, showSheet: self.$showSheet)
}
.alert(isPresented: $showAlert){
Alert(title: Text("Important message"), message: Text("Wear sunscreen"), dismissButton: .default(Text("Got it!")))
}
}
}
struct AddView: View {
@Binding var showAlert: Bool
@Binding var showSheet: Bool
var body: some View {
Button("Dismiss") {
self.showSheet = false
self.showAlert = true
}
}
}