[SwiftUI]Binding, dismiss Bug?

back with dismiss(Environment) and view reappears.

struct Person: Identifiable {
  let id = UUID()
  let name: String
}

struct ContentView: View {
  @State var people: [Person] = [.init(name: "mike")]
  @State var isPresented = false

  var body: some View {
    NavigationStack {
      List(people) { person in
        Text(person.name)
      }
      .navigationTitle("People")
      .navigationDestination(isPresented: $isPresented) {
        NewPerson(people: $people)
      }
      .toolbar {
        ToolbarItem {
          Button("Add") {
            isPresented.toggle()
          }
        }
      }
    }
  }
}

struct NewPerson: View {
  @Environment(\.dismiss) var dismiss
  @Binding var people: [Person]

  var body: some View {
    Button("Add and Back") {
      people.append(.init(name: "ace"))
      dismiss()
    }
  }
}

Calling dismiss() won't change the state of the isPresented property, so NewPerson is going to be re-presented as long as the property is true. Since you manage the presentation from a state property, you should be able to pass a binding to that state into NewPerson, and avoid using dismiss() at all. Instead, set the bound isPresented property back to false when the button is pressed.

if comment out // people.append(.init(name: "ace")), dismiss is works properly.

[SwiftUI]Binding, dismiss Bug?
 
 
Q