Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Toggle Side Bar Button NavigationSplitView macOS

In WWDC 2022, Apple introduced NavigationSplitView, an alternative to NavigationView. All are good before I get a problem: I don't know how to hide the toggle sidebar button.

What I want (like the Mail app, no sidebar button):

My code & result (I didn't add any code about the sidebar button in my project):

struct ContentView: View {
    @State private var selection: Int = 1
    @State private var search: String = ""
    
    @State private var columnVisibility = NavigationSplitViewVisibility.all
    
    var body: some View {
        NavigationSplitView(columnVisibility: $columnVisibility) {
            Sidebar(selection: $selection)
        } content: {
            Content(selection: $selection)
        } detail: {
            DetailView(selection: $selection)
        }
        .searchable(text: $search) {
            
        }
    }
}

Is there a way to hide it? I appreciate any help you can provide.

like image 552
Nhat Nguyen Duc Avatar asked Mar 14 '26 11:03

Nhat Nguyen Duc


1 Answers

This is now possible as of XCode Version 15.0 beta 6 (15A5219j).

To hide the 'Hide / Show Sidebar' button add .toolbar(removing:) with a ToolbarDefaultItemKind value of .sidebarToggle to your sidebar View:

NavigationSplitView(
  sidebar: {
    <#T##SomeSidebarView#>
      .toolbar(removing: .sidebarToggle)
  },
  detail: {
    <#T##SomeDetailView#>
  }
)
like image 124
Dennis Vennink Avatar answered Mar 16 '26 23:03

Dennis Vennink



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!