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 asHSplitView
, 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?