Switching between two `NavigationSplitView's breaks the titlebar/toolbar on macOS

89 views Asked by At

My macOS! app has a picker menu in the toolbar to switch between different views. If I try to switch from one view including a NavigationSplitView to another one of that kind, the menu title / tool bar breaks:

  • The toggle sidebar button vanishes
  • if I resize the sidebar the top of the sidebar shows a light grey rectangle (see image)
  • a Divider is added into the toolbar

It seems like Apple does not want us to use more than one high level NavigationSplitView in a window. Does anyone know a solution or workaround?

enter image description here

Here is a simple MRE to show the problem. Switch from View 1 to view 2 and try to make the sidebar wider.

struct ContentView: View {
    @State private var viewSelecion = 1
    
    var body: some View {
        NavigationStack {
            Group {
                switch viewSelecion {
                case 1: SubView1()
                case 2: SubView2()
//                case 3: Text("test")
                default: EmptyView()
                }
            }
        }
        .toolbar {
            ToolbarItem(placement: .navigation) {
                Picker("", selection: $viewSelecion) {
                    ForEach(1..<3) { view in
                        Text("View \(view)").tag(view)
                    }
                }
            }
        }
    }
}

struct SubView1: View {
    var body: some View {
        NavigationSplitView {
            Text("Sidebar 1")
        } detail: {
            Text("View 1")
        }
    }
}

struct SubView2: View {
    var body: some View {
        NavigationSplitView {
            Text("Sidebar 2")
        } detail: {
            Text("View 2")
        }
    }
}
0

There are 0 answers