Slide Over in iPadOS 15 breaks NavigationLink (SwiftUI)

210 views Asked by At

I’m having issues when using NavigationView and NavigationLinks on iPadOS 15. Currently running Dev Beta of iPadOS 15.3 (19D5026g), but I’ve had this issue since the release of 15.1. When I’m using my app as usual, nothing is wrong. But when I turn the app into a Slide Over, the detail works, but when I click “Back” and pop the detail back, I’m unable to click the NavLink (it doesn’t push the detail). When I turn the app back to full screen, everything is pretty much fine. Has anyone noticed something like that?

Edit: Just found out that Split Screen does the exact same thing.

Here’s my code:

struct ContentView: View {
    var body: some View {
        NavigationView {
            SideBar() 
                .navigationBarTitle("SideBar")
                .toolbar {
                    ToolbarItemGroup(placement: .navigationBarTrailing) {}
//Button which opens options
                }
            
            DetailView()
                .navigationBarTitle(“Detail”, displayMode: .large)   
        }
    }
}


//SideBar:
struct SideBar: View {
    var body: some View {
        VStack{

            Spacer()

            VStack {
                NavigationLink(destination: DetailView()) {           
                        Text(“DetailView”)
                            .font(.headline)
                }
                    NavigationLink(destination: OtherDetailView()) {
                                Text("Other Detail View")
                                .font(.headline)
                }
            }
            Spacer()
        }
    }
}

//DetailView and OtherDetailView
struct DetailView: View {
    var body: some View {
        VStack {
            
            Spacer()
            
            Text("Hello World!")
            
            Spacer()
        }
        .navigationBarTitle(“Detail”)
    }
}```

Thanks for your help!
1

There are 1 answers

0
Vojta Vokoun On

Found the solution myself some time ago, so I figured I'd post it here in case someone experiences the same behavior.

The right way to do what I was trying to do is apparently by using a list with this modifier:

.listStyle(SidebarListStyle())

That seemed weird to me, but I haven't found a different way to accomplish the thing I wanted to.