Since SwiftUI is declarative there is no dismiss
methode.
How can is add a dismiss/close button to the DetailView
?
Use Environment variable at PresentationMode. This GitHub link will maybe help you to solve the problem https://github.com/MannaICT13/Sheet-in-SwiftUI
This is simple solution:
struct ContentView2 : View {
@Environment (\.presentationMode) var presentationMode
var body : some View {
VStack {
Text("This is ContentView2")
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("Back")
})
}
}
}
struct ContentView: View {
@State var isShowingSheet : Bool = false
var body: some View {
Button(action: {
self.isShowingSheet.toggle()
}, label: {
Text("Click Here")
}).sheet(isPresented: $isShowingSheet, content: {
ContentView2()
})
}
}