After a couple of days struggling with programmatic navigation in SwiftUI and 3 column NavigationSplitView I found that .navigationDestination(isPresented:destination:) works only between sidebar and master or between master and detail, but can't be used in both. It can be illustrated on the following example:
struct ContentView: View {
@State private var columnVisibility = NavigationSplitViewVisibility.all
@State private var showMaster = false
@State private var showDetails = false
var body: some View {
NavigationSplitView(columnVisibility: $columnVisibility) {
Button("Show master") {
showMaster = true
}
.navigationDestination(isPresented: $showMaster) {
Button("Show details") {
showDetails = true
}
.navigationDestination(isPresented: $showDetails) {
Text("Detail")
}
}
} content: {
EmptyView()
} detail: {
EmptyView()
}
}
}
When I execute the code and click on "show master" button, it correctly shows "show detail" button. If I click on "show detail" button I expected "detail" will show, but nothing happens. What am I doing wrong?
It works correctly if only .navigationDestination(for:destination:). It doesn't work even if .navigationDestination(isPresented:destination:) is used to show master.