I'm using a sidebar for navigation in my iPad app and it seems to loose its selection when I use another NavigationLink in the detail view.!
Here's the sidebar code:
struct AppSidebarNavigation: View {
@State private var selection: NavigationTag? = .calculator
var body: some View {
NavigationView {
List {
NavigationLink(
tag: NavigationTag.calculator,
selection: $selection,
destination: CalculatorView.init
) {
Label("Calculator", systemImage: "function")
}
NavigationLink(
tag: NavigationTag.tools,
selection: $selection,
destination: ToolsView.init
) {
Label("Tools", systemImage: "rectangle.3.group")
}
NavigationLink(
tag: NavigationTag.recents,
selection: $selection,
destination: RecentsView.init
) {
Label("Recents", systemImage: "clock")
}
}
.listStyle(.sidebar)
.navigationTitle("App Name")
}
}
}
Here's the detail view code:
struct GridToolsView: View {
let tools: [Tool]
var columns: [GridItem] {
[GridItem(.flexible())]
}
var body: some View {
LazyHGrid(rows: columns) {
ForEach(tools) { tool in
NavigationLink {
SelectedView(for: tool)
} label: {
ToolView.gridItem(tool: tool)
}
.buttonStyle(.squishable(fadeOnPress: true))
}
}
.frame(maxWidth: .infinity, alignment: .topLeading)
}
}
Here's a video of the selected row losing its selection: Video
Does anyone know how to fix this problem?