I need to dismiss a sheet that doesn't call a view inside of it instead it makes it's own view. The reason this is necessary is because the view changes an attribute of an object in the previous view which won't update unless the attribute is changed in the same struct. Is there any way I could dismiss the view without swiping down in this way? Or a way I can pass a reference to the attribute so that when I change it in a separate struct it will update live in a previous one
I'm sorry for my super confusing explanation. I've simplified my actual implemented code to the following:
struct ContentView: View {
@Environment(\.dismiss) var dismiss
@State var word = ""
@State private var isSheetShowing = false
var body: some View {
NavigationView{
Form{
TextField("Change Word", text: $word)
Button(action: {
isSheetShowing.toggle()
}){
Text("Done")
.bold()
}
.sheet(isPresented: $isSheetShowing){
NavigationView{
List{
Text("Hello User")
}
.navigationBarItems(leading:
Button(action: {
dismiss()
}){
Text("Cancel")
.bold()
})
}
}
}
}
}
}
Pressing cancel in the sheet does not dismiss the view as I want it to.