Fix nav bar and colors in main_0.2 branch (#798)
* Fix nav bar and colors in main_0.1 branch (#795) * Update `MSFNavigationBar` for iOS 15 (#747) * Update `MSFNavigationBar` for iOS 15 * Fix appearance of test slideover drawer * Fix build with `#available` tags, and root view * Adding part of #747 for `changeStyleContinuously`
This commit is contained in:
Родитель
671fc5ae2e
Коммит
e517660ea0
|
@ -22,6 +22,12 @@ class DemoListViewController: UITableViewController {
|
|||
window.rootViewController = navigationController
|
||||
window.makeKeyAndVisible()
|
||||
|
||||
if #available(iOS 13, *) {
|
||||
let standardAppearance = navigationController.navigationBar.standardAppearance
|
||||
standardAppearance.backgroundColor = Colors.NavigationBar.background
|
||||
navigationController.navigationBar.scrollEdgeAppearance = standardAppearance
|
||||
}
|
||||
|
||||
if let viewController = viewController {
|
||||
navigationController.pushViewController(viewController, animated: false)
|
||||
}
|
||||
|
|
|
@ -180,6 +180,7 @@ class NavigationControllerDemoController: DemoController {
|
|||
}
|
||||
|
||||
navigationItem.navigationBarStyle = newStyle
|
||||
self.setNeedsStatusBarAppearanceUpdate()
|
||||
self.changeStyleContinuously(in: navigationItem)
|
||||
}
|
||||
}
|
||||
|
@ -451,6 +452,7 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe
|
|||
|
||||
@objc private func showModalView() {
|
||||
let modalNavigationController = UINavigationController(rootViewController: ModalViewController(style: .grouped))
|
||||
modalNavigationController.navigationBar.isTranslucent = true
|
||||
present(modalNavigationController, animated: true)
|
||||
}
|
||||
|
||||
|
|
|
@ -324,11 +324,15 @@ open class NavigationBar: UINavigationBar {
|
|||
rightBarButtonItemsStackView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
||||
rightBarButtonItemsStackView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
|
||||
updateViewsForLargeTitlePresentation(for: topItem)
|
||||
updateColors(for: topItem)
|
||||
|
||||
isTranslucent = false
|
||||
|
||||
// Cache the system shadow color
|
||||
if #available(iOS 13, *) {
|
||||
systemShadowColor = standardAppearance.shadowColor
|
||||
}
|
||||
|
||||
updateColors(for: topItem)
|
||||
updateViewsForLargeTitlePresentation(for: topItem)
|
||||
updateAccessibilityElements()
|
||||
}
|
||||
|
||||
|
@ -490,7 +494,12 @@ open class NavigationBar: UINavigationBar {
|
|||
titleView.style = .dark
|
||||
}
|
||||
|
||||
barTintColor = color
|
||||
if #available(iOS 13, *) {
|
||||
standardAppearance.backgroundColor = color
|
||||
scrollEdgeAppearance = standardAppearance
|
||||
} else {
|
||||
barTintColor = color
|
||||
}
|
||||
backgroundView.backgroundColor = color
|
||||
tintColor = style.tintColor
|
||||
if var titleTextAttributes = titleTextAttributes {
|
||||
|
@ -668,6 +677,9 @@ open class NavigationBar: UINavigationBar {
|
|||
|
||||
// MARK: Large/Normal Title handling
|
||||
|
||||
/// Cache for the system shadow color, since the default value is private.
|
||||
private var systemShadowColor: UIColor?
|
||||
|
||||
private func updateViewsForLargeTitlePresentation(for navigationItem: UINavigationItem?) {
|
||||
// UIView.isHidden has a bug where a series of repeated calls with the same parameter can "glitch" the view into a permanent shown/hidden state
|
||||
// i.e. repeatedly trying to hide a UIView that is already in the hidden state
|
||||
|
@ -695,12 +707,25 @@ open class NavigationBar: UINavigationBar {
|
|||
|
||||
private func updateShadow(for navigationItem: UINavigationItem?) {
|
||||
if needsShadow(for: navigationItem) {
|
||||
shadowImage = nil
|
||||
// Forcing layout to update size of shadow image view otherwise it stays with 0 height
|
||||
setNeedsLayout()
|
||||
subviews.forEach { $0.setNeedsLayout() }
|
||||
if #available(iOS 13, *) {
|
||||
standardAppearance.shadowColor = systemShadowColor
|
||||
} else {
|
||||
shadowImage = nil
|
||||
// Forcing layout to update size of shadow image view otherwise it stays with 0 height
|
||||
setNeedsLayout()
|
||||
subviews.forEach { $0.setNeedsLayout() }
|
||||
}
|
||||
} else {
|
||||
shadowImage = UIImage()
|
||||
if #available(iOS 13, *) {
|
||||
standardAppearance.shadowColor = nil
|
||||
} else {
|
||||
shadowImage = UIImage()
|
||||
}
|
||||
}
|
||||
|
||||
if #available(iOS 13, *) {
|
||||
// Update the scroll edge shadow to match standard
|
||||
scrollEdgeAppearance = standardAppearance
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче