blog icon indicating copy to clipboard operation
blog copied to clipboard

How to use HSplitView to define 3 panes view in SwiftUI for macOS

Open onmyway133 opened this issue 4 years ago • 2 comments

Specify minWidth to ensure miminum width, and use .layoutPriority(1) for the most important pane.

import SwiftUI

struct MainView: View {
    @EnvironmentObject var store: Store

    var body: some View {
        HSplitView {
            LeftPane()
                .padding()
                .frame(minWidth: 200, maxWidth: 500)
            MiddlePane(store: store)
                .padding()
                .frame(minWidth: 500)
                .layoutPriority(1)
            RightPane()
                .padding()
                .frame(minWidth: 300)
        }
        .background(R.color.background)
    }
}

onmyway133 avatar Sep 23 '20 04:09 onmyway133

Nice. Is this a decent solution for multi-platform (iOS, iPadOS and macOS)?

ricardopereira avatar Sep 23 '20 08:09 ricardopereira

Any way to get this working with a navigation view? My left and center panels are within a navigation view, and rightmost panel is different. I don't know how to integrate this with the hsplitview without the whole app glitching

aviwad avatar May 05 '22 06:05 aviwad