I'm asking your help today about a mystery behavior of the navigation link coupled with the sidebar on iPadOS.
First, here is my sidebar code:
NavigationView {
List(1..<5) { _ in
NavigationLink(destination: DetailView()) {
Label("Item", systemImage: "house")
}
}
.listStyle(SidebarListStyle())
}
This view contains navigation links to display a detail view as you can see.
My detail view contains another navigation link to a simple view containing a Text. Nothing more.
Here is the code of my detail view:
VStack {
Spacer()
NavigationLink(destination: Text("Hello")) {
Text("Touch me")
}
Spacer()
}
So far, so good. Now, let's compile this code and see what's going on:
Great ! The sidebar is well displayed and the first item is selected. Now let's touching the Touch me button on the detail view to trigger a navigation link inside the detail view.
Oh no... When touching the button, the navigation link is triggered as wanted, but the item in the sidebar become unselected. Is there something I'm doing wrong ? I also tried to use the selection binding in the list but it doesn't change anything. To compare, I would like to reproduce the iPad Music app navigation of the Album item of the sidebar. In there, you can select an album and go deeper in the navigation stack. And it keeps the sidebar item selected !
Can you help me to fix this issue ?
Thanks a lot !