iPadOS sidebar doesn’t work when items are tapped

I have a sidebar in my SwiftUI app that uses programmatic navigation to present views. However, it doesn’t work and open items when the device is in Split View. When I click on items in the sidebar when in Split View, the new view doesn’t push onto the stack. And when the sidebar slides in, it doesn’t go back when the item is clicked in the sidebar. It works perfectly fine on iOS and macOS and in the normal landscape view on iPadOS, but doesn’t work in Split View or in portrait. Any ideas here? I’m doing exactly what Apple says in their documentation (except for using a deprecated API because I don’t understand how the new one would work in my app, you’ll see in the code) but my app is basically broken when used in anything except landscape orientation. Here’s some code and a screen recording:

// ContentView 
   var body: some View {
       NavigationView {
           Sidebar() .navigationTitle("Formats")
           MLA()
       }
   }
}
// Sidebar
   @State private var isShowingMLAView = true
   @State private var isShowingAPAView = false
   @State private var isShowingChicagoView = false
   @State private var isShowingIEEEView = false
   @State private var isShowingCSEView = false
   @State private var isShowingHarvardView = false
   var body: some View {
       List {
           NavigationLink(destination: MLAWrapper().navigationTitle("Generate MLA"), isActive: $isShowingMLAView) {
               Label("MLA", systemImage: "books.vertical.fill")}
           NavigationLink(destination: APAWrapper().navigationTitle("Generate APA"), isActive: $isShowingAPAView) {
               Label("APA", systemImage: "atom")}
           NavigationLink(destination: ChicagoWrapper().navigationTitle("Generate Chicago"), isActive: $isShowingChicagoView) {
               Label("Chicago", systemImage: "building.columns")}
           NavigationLink(destination: IEEEWrapper().navigationTitle("Generate IEEE"), isActive: $isShowingIEEEView) {
               Label("IEEE", systemImage: "desktopcomputer")
           }
           NavigationLink(destination: HarvardWrapper().navigationTitle("Generate Harvard"), isActive: $isShowingHarvardView) {
               Label("Harvard", systemImage: "book.fill")
           }
       }
       .listStyle(SidebarListStyle())
   }
}

https://reddit.com/link/yllalb/video/562czppa9ux91/player

Posted Nov 4, 2022, 1:36 AM UTC · edited

310
Loading comments…