In the following working example, editing the name of the published Test.Data will work, editing the name of the parent will work, but editing the name of the child will cause the NavigationView to pop.
Is there any way for the NavigationView to not pop when editing a nested?
class Test:ObservableObject {
@Published var data:Data = .init()
struct Data:Identifiable {
var id:UUID = UUID()
var name:String = ""
var parents:[Parent] = [.init()]
}
struct ContentView:SwiftUI.View {
@EnvironmentObject var test:Test
var body: some SwiftUI.View {
NavigationView {
Form {
$test.data.name.view(with: "Name")
ForEach(enumerating: test.data.parents) { index, item in
NavigationLink(destination: Form { Parent.View(parent: self.$test.data.parents[index]) }) {
Text(item.name)
}
}
}
}
}
}
}
struct Parent:Identifiable {
var id:UUID = UUID()
var name:String = ""
var children:[Child] = [.init()]
struct View: SwiftUI.View {
@Binding var parent:Parent
var body: some SwiftUI.View {
Group {
$parent.name.view(with: "Name of the parent")
ForEach(enumerating: parent.children) { index, item in
NavigationLink(destination: Form { Child.View(child: self.$parent.children[index]) }) {
Text(item.name)
}
}
}
}
}
}
struct Child:Identifiable {
var id:UUID = UUID()
var name:String = ""
struct View: SwiftUI.View {
@Binding var child:Child
var body: some SwiftUI.View {
Group {
$child.name.view(with: "Name of the child")
}
}
}
}