0

I want a two column-view in a Swift UI app, where the left column displays a list and the right column displays a detail view. This works fine like this:

struct ContentView: View {
  
  @State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn

    var body: some View {
      NavigationSplitView( columnVisibility: $columnVisibility)  {
        List {
          ForEach(itemList, id: \.self ){item in
            NavigationLink(item.name){ ItemDetail(item: item)}
          }
        }      } detail: {
        Text("detail placeholder ")
      }
      
      
      .navigationSplitViewStyle(.automatic)
    }
}

In iPad portrait mode I want to show only the list column first. This should then behave like a stack navigation.

In addition, on the Mac, if a certain window width is not reached, only the list column should be displayed. This should then also behave like a stack navigation.

How is this feasible?

mica
  • 3,898
  • 4
  • 34
  • 62
  • 2
    I'm afraid this is not the standard `NavigationSplitView` behavior. You have to check yourself based on `@Environment(\.horizontalSizeClass) var sizeClass` and switch between different views. – ChrisR Dec 10 '22 at 23:49

0 Answers0