wigging / swift-macos

Swift Programming for macOS

Home Page:https://gavinw.me/swift-macos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customize Sidebar Default Width

briantkelley opened this issue · comments

The Finder sidebar has a default width that hugs its content (180 pt on my machine) and a minimum width of ~ 112 pt. Is it possible to implement Finder sidebar behavior with SwiftUI? (Custom default/initial width, snap to default width)

Or more simply, customizing the initial width to something other than 140 pt would be a great start too!

I added a sidebar-width example. It uses minWidth to define the initial width and maxWidth to define the max width of the sidebar. Does that demonstrate what you're trying to accomplish?

Thanks! In the example I'd like to show the window with the sidebar initially set to something like 225 pt or 250 pt and still allow it to be resizable down to 200 pt and up to 300 pt.

Apps like Notes or Finder generally have the same behavior... the window shows with the sidebar width greater than the minimum and less than the maximum. I haven't figured out how to accomplish that in SwiftUI.

I understand what you're saying but I don't think it is currently possible in SwiftUI. One thing I tried was to remove .listStyle(SidebarListStyle()) from the example. This prevents the sidebar from collapsing but the nice styling effect is gone.

It's a bummer it doesn't seem to be supported in SwiftUI but thank you for taking a look! I really appreciate it!

I labeled this as a bug for now. Hopefully there will be a SwiftUI update that fixes the problem. I'll keep this open so I don't forget to about it.

As of macOS 13, this can be accomplished in SwiftUI with the navigationSplitViewColumnWidth function. See the article I posted at https://gavinw.me/swift-macos/swiftui/twocol-navsplit.html for more details.