In iOS, when you tap a row in a list to navigation to a page, the row gets highlighted to indicate which row is selected. This is not working for me when I have a NavigationStack(path:root:) that uses NavigationLink(_ titleKey:value:) and navigationDestination(for:destination).
Highlight doesn't work in the code below for me neither in Simulator nor device:
import SwiftUI
struct ExperimentView: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink("Page", value: 0)
NavigationLink("Page", value: 1)
NavigationLink("Page", value: 2)
}
.navigationTitle("List")
.navigationDestination(for: Int.self) { int in
Text(int.description)
}
}
}
}
But it works just fine when I use NavigationStack(root:) that uses NavigationLink(_ titleKey:destination).
This is one of the core differences between
NavigationStackandNavigationSplitView.The
selectiononly works withNavigationSplitViewI assume it is because theListdoes not stay on the screen withNavigationStackhttps://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types#Update-selection-based-navigation