@DTS Engineer Below you will find a more detailed code:
@State private var selectedItem: String?
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationSplitView {
List(selection: $selectedItem) {
Button("Item 1") { selectedItem = "Detail View 1" }
Button("Item 2") { selectedItem = "Detail View 2" }
}
} detail: {
NavigationStack(path: $navigationPath) {
DetailView(navigationPath: $navigationPath)
.navigationDestination(for: String.self) { value in
VStack {
Image(systemName: "photo")
Text("New Screen: \(value)")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
}
}
struct DetailView: View {
@Binding var navigationPath: NavigationPath
var body: some View {
VStack {
Text("Title")
.font(.title)
Text("Detail view content")
.foregroundStyle(.secondary)
Button("Change Screen"){
navigationPath.append("Second Screen")
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
While observing navigationPath it did not pop the view of the stack after adding it.
@DTS Engineer