Persist sidebar visibility across app launches

Closes #372
This commit is contained in:
Shadowfacts 2023-04-23 13:57:24 -04:00
parent 49334766ef
commit ea5afeeb88
1 changed files with 26 additions and 0 deletions

View File

@ -24,6 +24,15 @@ class MainSplitViewController: UISplitViewController {
viewController(for: .secondary) as? SplitNavigationController viewController(for: .secondary) as? SplitNavigationController
} }
private var sidebarVisibile: Bool {
get {
(UserDefaults.standard.object(forKey: "MainSplitViewControllerSidebarVisible") as? Bool) ?? true
}
set {
UserDefaults.standard.set(newValue, forKey: "MainSplitViewControllerSidebarVisible")
}
}
init(mastodonController: MastodonController) { init(mastodonController: MastodonController) {
self.mastodonController = mastodonController self.mastodonController = mastodonController
@ -45,6 +54,11 @@ class MainSplitViewController: UISplitViewController {
sidebar.sidebarDelegate = self sidebar.sidebarDelegate = self
setViewController(sidebar, for: .primary) setViewController(sidebar, for: .primary)
primaryBackgroundStyle = .sidebar primaryBackgroundStyle = .sidebar
if sidebarVisibile {
show(.primary)
} else {
hide(.primary)
}
let splitNav = SplitNavigationController() let splitNav = SplitNavigationController()
setViewController(splitNav, for: .secondary) setViewController(splitNav, for: .secondary)
@ -355,6 +369,18 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
return return
} }
} }
func splitViewController(_ svc: UISplitViewController, willHide column: UISplitViewController.Column) {
if column == .primary {
sidebarVisibile = false
}
}
func splitViewController(_ svc: UISplitViewController, willShow column: UISplitViewController.Column) {
if column == .primary {
sidebarVisibile = true
}
}
} }
extension MainSplitViewController: MainSidebarViewControllerDelegate { extension MainSplitViewController: MainSidebarViewControllerDelegate {