Until (one would hope) Apple gets around to it, here's something that'll work.
Using Debug View Hierarchy in the debug toolbar, I found that a private NSSplitViewController is being used for layout. I opted to pass an action down the responder chain to toggle its associated sidebar:
private func documentGroup() -> some Scene {
return DocumentGroup(newDocument: Document()) {
DocumentView()
.toolbar {
ToolbarItem(placement: .navigation) {
Button(action: toggleSidebar, label: {
Image(systemName: "sidebar.left")
})
}
}
.environmentObject($0.document.store)
}
}
private func toggleSidebar() {
#if os(iOS)
#else
NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
#endif
}
One might also be able to use a package like Swift-Introspection to get a handle on the NSSplitViewController in your SwiftUI code and send the message more directly.