1

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:

sidebar

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.

sidebar item unselected

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 !

Vinestro
  • 1,072
  • 1
  • 10
  • 32
  • Does [this](https://stackoverflow.com/a/63230898/7129318) answer your question? – Yrb Nov 29 '21 at 17:10
  • I'll give it a try, but I can't believe that Apple is doing it that way. For information, this behavior seems to appears in iOS 15 but not on iOS 14... Weird. – Vinestro Nov 29 '21 at 19:18
  • This issue only on iOS15, I test it on iOS14 and iOS16 it work fine!, @Yrb this answer fix the issue on iOS15 and make it behave as iOS14 and iOS16 – Basel Nov 05 '22 at 10:57

0 Answers0