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.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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if #available(iOS 13, *) {
|
||||||
|
standardAppearance.backgroundColor = color
|
||||||
|
scrollEdgeAppearance = standardAppearance
|
||||||
|
} else {
|
||||||
barTintColor = color
|
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,15 +707,28 @@ open class NavigationBar: UINavigationBar {
|
||||||
|
|
||||||
private func updateShadow(for navigationItem: UINavigationItem?) {
|
private func updateShadow(for navigationItem: UINavigationItem?) {
|
||||||
if needsShadow(for: navigationItem) {
|
if needsShadow(for: navigationItem) {
|
||||||
|
if #available(iOS 13, *) {
|
||||||
|
standardAppearance.shadowColor = systemShadowColor
|
||||||
|
} else {
|
||||||
shadowImage = nil
|
shadowImage = nil
|
||||||
// Forcing layout to update size of shadow image view otherwise it stays with 0 height
|
// Forcing layout to update size of shadow image view otherwise it stays with 0 height
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
subviews.forEach { $0.setNeedsLayout() }
|
subviews.forEach { $0.setNeedsLayout() }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if #available(iOS 13, *) {
|
||||||
|
standardAppearance.shadowColor = nil
|
||||||
} else {
|
} else {
|
||||||
shadowImage = UIImage()
|
shadowImage = UIImage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if #available(iOS 13, *) {
|
||||||
|
// Update the scroll edge shadow to match standard
|
||||||
|
scrollEdgeAppearance = standardAppearance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func needsShadow(for navigationItem: UINavigationItem?) -> Bool {
|
private func needsShadow(for navigationItem: UINavigationItem?) -> Bool {
|
||||||
switch navigationItem?.navigationBarShadow ?? .automatic {
|
switch navigationItem?.navigationBarShadow ?? .automatic {
|
||||||
case .automatic:
|
case .automatic:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче