Hello,
I have to dismiss multiple modal which are presented one after the other from the last modal view.
I have a @state bool property which is being passed as @binding to the concurrent views. When @state property property is set to true .sheet is being fired and modal will be presented.
Could anyone please let me know how to return from Modal2 back to Content view by clicking Dismiss button?
struct ContentView: View {
@State private var showModal = false
var body: some View {
Button("Show Modal") {
self.showModal = true
}.sheet(isPresented: $showModal) {
ModalView(showModal: self.$showModal)
}
}
}
struct ModalView: View {
@Binding var showModal: Bool
var body: some View {
VStack {
Text("Inside Modal View")
.padding()
Button("Show Modal") {
self.showModal = true
}.sheet(isPresented: $showModal) {
Modal2(showModal: self.$showModal)
}
Button("Dismiss") {
self.showModal = false
}
}
}
struct Modal2: View {
@Binding var showModal: Bool
var body: some View {
VStack {
Text("Inside Modal 2")
.padding()
Button("Dismiss") {
self.showModal.toggle()
}
}
}
}
I have to dismiss multiple modal which are presented one after the other from the last modal view.
I have a @state bool property which is being passed as @binding to the concurrent views. When @state property property is set to true .sheet is being fired and modal will be presented.
Could anyone please let me know how to return from Modal2 back to Content view by clicking Dismiss button?
struct ContentView: View {
@State private var showModal = false
var body: some View {
Button("Show Modal") {
self.showModal = true
}.sheet(isPresented: $showModal) {
ModalView(showModal: self.$showModal)
}
}
}
struct ModalView: View {
@Binding var showModal: Bool
var body: some View {
VStack {
Text("Inside Modal View")
.padding()
Button("Show Modal") {
self.showModal = true
}.sheet(isPresented: $showModal) {
Modal2(showModal: self.$showModal)
}
Button("Dismiss") {
self.showModal = false
}
}
}
struct Modal2: View {
@Binding var showModal: Bool
var body: some View {
VStack {
Text("Inside Modal 2")
.padding()
Button("Dismiss") {
self.showModal.toggle()
}
}
}
}