How to set the holding priority with NavigationSplitView

My question concerns a macOS SwiftUI app. I would like to have a split view with 2 horizontal panes without sidebar: content on the left and inspector on the right. The inspector should act like the inspector panel on the right side side of the Xcode's window: when the window is resized, the inspector keeps it's current width and the user can resize the inspector using the split divider.

  • Using macOS Monterey SDK, I tried to achieve this with HSplitView but the problem is that the left/right panels are both resized when the window is resized.
struct ContentView: View {
    var body: some View {
          HSplitView {
              Rectangle().fill(.red)
              Rectangle().fill(.yellow)
          }      
    }
}
  • Using Ventura SDK, I just tried the new view NavigationSplitView. I'm using .constant(.doubleColumn) to hide the sidebar but the problem is the same as HSplitView, the left/right panel are both resized when the window is resized.
struct ContentView: View {
    var body: some View {
        NavigationSplitView(columnVisibility: .constant(.doubleColumn)) {
            Text("not used")
        } content: {
            Rectangle().fill(.red)
        } detail: {
            Rectangle().fill(.yellow)
        }
    }
}

When using NSSplitViewController with AppKit, the holdingPriority (https://developer.apple.com/documentation/appkit/nssplitviewitem/1388887-holdingpriority?language=objc) allows to manage this case: The view with the lowest priority is the first to gain additional width if the split view grows or shrinks.

Is it possible to achieve this with SwiftUI?

Post not yet marked as solved Up vote post of benoit Down vote post of benoit
1.4k views

Replies

Is there a solution for this problem. I have the same problem. navigationsplitviewcolumnwidth(_:) does not have any effect on the detail content. My assumption is more and more that detail is not considered to be used as an inspector panel. To archive this we may have to implement a separate overlay. Would be great to hear someone from Apple to clarify or give a solution for this.

Thanks.