Dismissing a Sheet That Doesn't Call Another View

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.

Answered by WeagleWeagle in 718346022

Nevermind. I just need to toggle isSheetShowing again

Accepted Answer

Nevermind. I just need to toggle isSheetShowing again

Your dismiss dismisses your ContentView

another better way is to create a separate View

struct SheetView: View {
   @Environment(\.dismiss) var dismiss
   var body: come View {
       ...
       Button {
           dismiss()
       } label: [
           ...
       }
  }
}

Then it'll work.

sth().sheet(...) {
    SheetView()
}
Dismissing a Sheet That Doesn't Call Another View
 
 
Q