swift-macos icon indicating copy to clipboard operation
swift-macos copied to clipboard

Customize Sidebar Default Width

Open briantkelley opened this issue 5 years ago • 5 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!

briantkelley avatar Apr 28 '20 17:04 briantkelley

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?

wigging avatar Apr 29 '20 00:04 wigging

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.

briantkelley avatar Apr 30 '20 05:04 briantkelley

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.

wigging avatar Apr 30 '20 16:04 wigging

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

briantkelley avatar May 06 '20 17:05 briantkelley

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.

wigging avatar May 06 '20 17:05 wigging

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.

wigging avatar Nov 23 '22 02:11 wigging