Add Button next to "toggle sidebar" button in NavigationSplitView

Hi, I am trying to add a custom (create) button next to the automatic "toggle sidebar" button in a NavigationSplitView.

When the sidebar is collapsed that button should be displayed in a group with that automatic toggle button.

Basically I want exact the same behaviour as in the Apple "Reminders" App.

How could I archive that?

Thanks for your help :-)

Jan

Answered by DTS Engineer in 866652022

You might not get a 1-1 behavior as the Reminders App, but I think the approach is to remove the sidebar toggle using toolbar(removing: .sidebarToggle) and add your custom buttons using ToolbarItemGroup(placement: .navigation) { }.

Accepted Answer

You might not get a 1-1 behavior as the Reminders App, but I think the approach is to remove the sidebar toggle using toolbar(removing: .sidebarToggle) and add your custom buttons using ToolbarItemGroup(placement: .navigation) { }.

Hi, thanks for your answer! Technically it works this way, but with a few drawbacks (button group displayed outside the sidebar and no animation when toggling the sidebar visibility).

I'm doing the toggling like this:

Button {
    self.columnVisibility = self.columnVisibility == NavigationSplitViewVisibility.detailOnly
    ? NavigationSplitViewVisibility.automatic
    : NavigationSplitViewVisibility.detailOnly
} label: {
    Image(systemName: "sidebar.left")
}

Is there any way to also enable the sliding animation it does when using the built-in toggle switch?

Any other ideas how apple does it in their apps?

Thanks! Jan

Nevermind. Got it working with animation :)

Add Button next to "toggle sidebar" button in NavigationSplitView
 
 
Q