ThreeColumnNavigation icon indicating copy to clipboard operation
ThreeColumnNavigation copied to clipboard

[Resolved] Toggle the sidebar on iPadOS

Open FredericRuaudel opened this issue 3 years ago • 1 comments

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 !

FredericRuaudel avatar Oct 01 '21 12:10 FredericRuaudel

It works for iPadOS 14 & 15 but do nothing on iOS (aka on phones)

FredericRuaudel avatar Oct 01 '21 12:10 FredericRuaudel