Update AdaptableNavigationController when interface preference changes
This commit is contained in:
parent
494708a362
commit
0e95cd0adf
|
@ -7,7 +7,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import Combine
|
import TuskerPreferences
|
||||||
|
|
||||||
@available(iOS 17.0, *)
|
@available(iOS 17.0, *)
|
||||||
class AdaptableNavigationController: UIViewController {
|
class AdaptableNavigationController: UIViewController {
|
||||||
|
@ -15,6 +15,7 @@ class AdaptableNavigationController: UIViewController {
|
||||||
private let viewControllersToPrependInCompact: [UIViewController]
|
private let viewControllersToPrependInCompact: [UIViewController]
|
||||||
|
|
||||||
private var initialViewControllers: [UIViewController] = []
|
private var initialViewControllers: [UIViewController] = []
|
||||||
|
private var currentWidescreenNavigationMode: WidescreenNavigationMode?
|
||||||
private lazy var regular = makeRegularNavigationController()
|
private lazy var regular = makeRegularNavigationController()
|
||||||
private lazy var compact = makeCompactNavigationController()
|
private lazy var compact = makeCompactNavigationController()
|
||||||
private var _current: (any NavigationControllerProtocol)?
|
private var _current: (any NavigationControllerProtocol)?
|
||||||
|
@ -39,6 +40,8 @@ class AdaptableNavigationController: UIViewController {
|
||||||
registerForTraitChanges([UITraitHorizontalSizeClass.self]) { (self: AdaptableNavigationController, previousTraitCollection) in
|
registerForTraitChanges([UITraitHorizontalSizeClass.self]) { (self: AdaptableNavigationController, previousTraitCollection) in
|
||||||
self.updateNavigationController()
|
self.updateNavigationController()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateNavigationController() {
|
private func updateNavigationController() {
|
||||||
|
@ -47,6 +50,7 @@ class AdaptableNavigationController: UIViewController {
|
||||||
if let _current {
|
if let _current {
|
||||||
_current.removeViewAndController()
|
_current.removeViewAndController()
|
||||||
stack = _current.viewControllers
|
stack = _current.viewControllers
|
||||||
|
_current.viewControllers = []
|
||||||
isTransferring = true
|
isTransferring = true
|
||||||
} else {
|
} else {
|
||||||
stack = initialViewControllers
|
stack = initialViewControllers
|
||||||
|
@ -79,6 +83,7 @@ class AdaptableNavigationController: UIViewController {
|
||||||
|
|
||||||
private func makeRegularNavigationController() -> any NavigationControllerProtocol {
|
private func makeRegularNavigationController() -> any NavigationControllerProtocol {
|
||||||
// TODO: need to figure out how to update the navigation controller if the pref changes
|
// TODO: need to figure out how to update the navigation controller if the pref changes
|
||||||
|
self.currentWidescreenNavigationMode = Preferences.shared.widescreenNavigationMode
|
||||||
switch Preferences.shared.widescreenNavigationMode {
|
switch Preferences.shared.widescreenNavigationMode {
|
||||||
case .stack:
|
case .stack:
|
||||||
return EnhancedNavigationViewController()
|
return EnhancedNavigationViewController()
|
||||||
|
@ -92,6 +97,18 @@ class AdaptableNavigationController: UIViewController {
|
||||||
private func makeCompactNavigationController() -> any NavigationControllerProtocol {
|
private func makeCompactNavigationController() -> any NavigationControllerProtocol {
|
||||||
EnhancedNavigationViewController()
|
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, *)
|
@available(iOS 17.0, *)
|
||||||
|
|
Loading…
Reference in New Issue