diff --git a/Tusker/Screens/Utilities/AdaptableNavigationController.swift b/Tusker/Screens/Utilities/AdaptableNavigationController.swift index 145e75cd..f991570f 100644 --- a/Tusker/Screens/Utilities/AdaptableNavigationController.swift +++ b/Tusker/Screens/Utilities/AdaptableNavigationController.swift @@ -7,7 +7,7 @@ // import UIKit -import Combine +import TuskerPreferences @available(iOS 17.0, *) class AdaptableNavigationController: UIViewController { @@ -15,6 +15,7 @@ class AdaptableNavigationController: UIViewController { private let viewControllersToPrependInCompact: [UIViewController] private var initialViewControllers: [UIViewController] = [] + private var currentWidescreenNavigationMode: WidescreenNavigationMode? private lazy var regular = makeRegularNavigationController() private lazy var compact = makeCompactNavigationController() private var _current: (any NavigationControllerProtocol)? @@ -39,6 +40,8 @@ class AdaptableNavigationController: UIViewController { registerForTraitChanges([UITraitHorizontalSizeClass.self]) { (self: AdaptableNavigationController, previousTraitCollection) in self.updateNavigationController() } + + NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil) } private func updateNavigationController() { @@ -47,6 +50,7 @@ class AdaptableNavigationController: UIViewController { if let _current { _current.removeViewAndController() stack = _current.viewControllers + _current.viewControllers = [] isTransferring = true } else { stack = initialViewControllers @@ -79,6 +83,7 @@ class AdaptableNavigationController: UIViewController { private func makeRegularNavigationController() -> any NavigationControllerProtocol { // TODO: need to figure out how to update the navigation controller if the pref changes + self.currentWidescreenNavigationMode = Preferences.shared.widescreenNavigationMode switch Preferences.shared.widescreenNavigationMode { case .stack: return EnhancedNavigationViewController() @@ -92,6 +97,18 @@ class AdaptableNavigationController: UIViewController { private func makeCompactNavigationController() -> any NavigationControllerProtocol { EnhancedNavigationViewController() } + + @objc private func preferencesChanged() { + if currentWidescreenNavigationMode != Preferences.shared.widescreenNavigationMode { + if let _current, + _current === regular { + regular = makeRegularNavigationController() + updateNavigationController() + } else { + regular = makeRegularNavigationController() + } + } + } } @available(iOS 17.0, *)