Commit eae3cc12 by Orkhan Alikhanov

Reworked toolbar theming

parent 28835e94
...@@ -30,7 +30,18 @@ ...@@ -30,7 +30,18 @@
import UIKit import UIKit
public enum IconButtonThemingStyle {
/// Theming when background content is in background color.
case onBackground
/// Theming when background content is in primary color.
case onPrimary
}
open class IconButton: Button { open class IconButton: Button {
/// A reference to IconButtonThemingStyle.
open var themingStyle = IconButtonThemingStyle.onBackground
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
pulseAnimation = .center pulseAnimation = .center
...@@ -39,7 +50,13 @@ open class IconButton: Button { ...@@ -39,7 +50,13 @@ open class IconButton: Button {
open override func apply(theme: Theme) { open override func apply(theme: Theme) {
super.apply(theme: theme) super.apply(theme: theme)
switch themingStyle {
case .onBackground:
tintColor = theme.secondary tintColor = theme.secondary
pulseColor = theme.secondary pulseColor = theme.secondary
case .onPrimary:
tintColor = theme.onPrimary
pulseColor = theme.onPrimary
}
} }
} }
...@@ -179,21 +179,8 @@ open class NavigationBar: UINavigationBar, Themeable { ...@@ -179,21 +179,8 @@ open class NavigationBar: UINavigationBar, Themeable {
} }
private func apply(theme: Theme, to item: UINavigationItem) { private func apply(theme: Theme, to item: UINavigationItem) {
Theme.apply(theme: theme, to: item.toolbar)
item.toolbar.backgroundColor = .clear item.toolbar.backgroundColor = .clear
(item.toolbar.leftViews + item.toolbar.rightViews + item.toolbar.centerViews).compactMap { $0 as? IconButton }
.filter { $0.isThemingEnabled }
.forEach {
$0.tintColor = theme.onPrimary
$0.pulseColor = theme.onPrimary
}
if !((item.titleLabel as? Themeable)?.isThemingEnabled == false) {
item.titleLabel.textColor = theme.onPrimary
}
if !((item.detailLabel as? Themeable)?.isThemingEnabled == false) {
item.detailLabel.textColor = theme.onPrimary
}
} }
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
open class Toolbar: Bar { open class Toolbar: Bar, Themeable {
/// A convenience property to set the titleLabel.text. /// A convenience property to set the titleLabel.text.
@IBInspectable @IBInspectable
open var title: String? { open var title: String? {
...@@ -63,6 +63,24 @@ open class Toolbar: Bar { ...@@ -63,6 +63,24 @@ open class Toolbar: Bar {
@IBInspectable @IBInspectable
public let detailLabel = UILabel() public let detailLabel = UILabel()
open override var leftViews: [UIView] {
didSet {
prepareIconButtons(leftViews)
}
}
open override var centerViews: [UIView] {
didSet {
prepareIconButtons(centerViews)
}
}
open override var rightViews: [UIView] {
didSet {
prepareIconButtons(rightViews)
}
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -129,6 +147,25 @@ open class Toolbar: Bar { ...@@ -129,6 +147,25 @@ open class Toolbar: Bar {
prepareDetailLabel() prepareDetailLabel()
} }
open func apply(theme: Theme) {
backgroundColor = theme.primary
(leftViews + rightViews + centerViews).forEach {
guard let v = $0 as? IconButton, v.isThemingEnabled else {
return
}
v.apply(theme: theme)
}
if !((titleLabel as? Themeable)?.isThemingEnabled == false) {
titleLabel.textColor = theme.onPrimary
}
if !((detailLabel as? Themeable)?.isThemingEnabled == false) {
detailLabel.textColor = theme.onPrimary
}
}
/// A reference to titleLabel.textAlignment observation. /// A reference to titleLabel.textAlignment observation.
private var titleLabelTextAlignmentObserver: NSKeyValueObservation! private var titleLabelTextAlignmentObserver: NSKeyValueObservation!
} }
...@@ -152,4 +189,12 @@ private extension Toolbar { ...@@ -152,4 +189,12 @@ private extension Toolbar {
detailLabel.font = RobotoFont.regular(with: 12) detailLabel.font = RobotoFont.regular(with: 12)
detailLabel.textColor = Color.darkText.secondary detailLabel.textColor = Color.darkText.secondary
} }
func prepareIconButtons(_ views: [UIView]) {
views.forEach {
($0 as? IconButton)?.themingStyle = .onPrimary
}
applyCurrentTheme()
}
} }
...@@ -73,24 +73,6 @@ open class ToolbarController: StatusBarController { ...@@ -73,24 +73,6 @@ open class ToolbarController: StatusBarController {
prepareToolbar() prepareToolbar()
} }
open override func apply(theme: Theme) {
super.apply(theme: theme)
toolbar.backgroundColor = theme.primary
toolbar.titleLabel.textColor = theme.onPrimary
toolbar.detailLabel.textColor = theme.onPrimary
(toolbar.leftViews + toolbar.rightViews + toolbar.centerViews).compactMap {
$0 as? IconButton
}.filter {
$0.isThemingEnabled
}.forEach {
$0.tintColor = theme.onPrimary
$0.titleColor = theme.onPrimary
$0.pulseColor = theme.onPrimary
}
}
} }
fileprivate extension ToolbarController { fileprivate extension ToolbarController {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment