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:
Mike Schreiber 2021-11-12 16:01:31 -08:00 коммит произвёл GitHub
Родитель 671fc5ae2e
Коммит e517660ea0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 42 добавлений и 9 удалений

Просмотреть файл

@ -22,6 +22,12 @@ class DemoListViewController: UITableViewController {
window.rootViewController = navigationController window.rootViewController = navigationController
window.makeKeyAndVisible() window.makeKeyAndVisible()
if #available(iOS 13, *) {
let standardAppearance = navigationController.navigationBar.standardAppearance
standardAppearance.backgroundColor = Colors.NavigationBar.background
navigationController.navigationBar.scrollEdgeAppearance = standardAppearance
}
if let viewController = viewController { if let viewController = viewController {
navigationController.pushViewController(viewController, animated: false) navigationController.pushViewController(viewController, animated: false)
} }

Просмотреть файл

@ -180,6 +180,7 @@ class NavigationControllerDemoController: DemoController {
} }
navigationItem.navigationBarStyle = newStyle navigationItem.navigationBarStyle = newStyle
self.setNeedsStatusBarAppearanceUpdate()
self.changeStyleContinuously(in: navigationItem) self.changeStyleContinuously(in: navigationItem)
} }
} }
@ -451,6 +452,7 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe
@objc private func showModalView() { @objc private func showModalView() {
let modalNavigationController = UINavigationController(rootViewController: ModalViewController(style: .grouped)) let modalNavigationController = UINavigationController(rootViewController: ModalViewController(style: .grouped))
modalNavigationController.navigationBar.isTranslucent = true
present(modalNavigationController, animated: true) present(modalNavigationController, animated: true)
} }

Просмотреть файл

@ -324,11 +324,15 @@ open class NavigationBar: UINavigationBar {
rightBarButtonItemsStackView.setContentHuggingPriority(.defaultHigh, for: .horizontal) rightBarButtonItemsStackView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
rightBarButtonItemsStackView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal) rightBarButtonItemsStackView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
updateViewsForLargeTitlePresentation(for: topItem)
updateColors(for: topItem)
isTranslucent = false isTranslucent = false
// Cache the system shadow color
if #available(iOS 13, *) {
systemShadowColor = standardAppearance.shadowColor
}
updateColors(for: topItem)
updateViewsForLargeTitlePresentation(for: topItem)
updateAccessibilityElements() updateAccessibilityElements()
} }
@ -490,7 +494,12 @@ open class NavigationBar: UINavigationBar {
titleView.style = .dark titleView.style = .dark
} }
barTintColor = color if #available(iOS 13, *) {
standardAppearance.backgroundColor = color
scrollEdgeAppearance = standardAppearance
} else {
barTintColor = color
}
backgroundView.backgroundColor = color backgroundView.backgroundColor = color
tintColor = style.tintColor tintColor = style.tintColor
if var titleTextAttributes = titleTextAttributes { if var titleTextAttributes = titleTextAttributes {
@ -668,6 +677,9 @@ open class NavigationBar: UINavigationBar {
// MARK: Large/Normal Title handling // 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?) { 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 // 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 // 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?) { private func updateShadow(for navigationItem: UINavigationItem?) {
if needsShadow(for: navigationItem) { if needsShadow(for: navigationItem) {
shadowImage = nil if #available(iOS 13, *) {
// Forcing layout to update size of shadow image view otherwise it stays with 0 height standardAppearance.shadowColor = systemShadowColor
setNeedsLayout() } else {
subviews.forEach { $0.setNeedsLayout() } shadowImage = nil
// Forcing layout to update size of shadow image view otherwise it stays with 0 height
setNeedsLayout()
subviews.forEach { $0.setNeedsLayout() }
}
} else { } 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
} }
} }