ThreeColumnNavigation
ThreeColumnNavigation copied to clipboard
[Resolved] Toggle the sidebar on iPadOS
Hi !
Thanks for this useful project. It seems that I've found how to update this code to have the sidebar toggle button working on iPadOS by changing the display mode like this:
#if os(macOS)
list.toolbar {
Button(action: toggleSidebar) {
Image(systemName: "sidebar.left")
}
}
#else
list.toolbar {
Button(action: {
UIApplication.shared.setFirstSplitViewPreferredDisplayMode(.oneBesideSecondary)
}) {
Image(systemName: "sidebar.left")
}
}
#endif
}
And to make it animated, just update the setFirstSplitViewPreferredDisplayMode()
method like this:
if let splitViewController = splitViewController {
UIView.animate(withDuration: 0.3, delay: 0, options: []) {
splitViewController.preferredDisplayMode = preferredDisplayMode
} completion: { _ in }
} else {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.3, delay: 0, options: []) {
splitViewController?.preferredDisplayMode = preferredDisplayMode
} completion: { _ in }
}
}
Hope it helps anyone !
It works for iPadOS 14 & 15 but do nothing on iOS (aka on phones)