Commit b5908d83 by Orkhan Alikhanov

Made buttons themeable

parent c217102c
......@@ -142,6 +142,14 @@ open class BaseIconLayerButton: Button {
reloadImage()
}
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
setIconColor(theme.secondary, for: .selected)
setIconColor(theme.onSurface.withAlphaComponent(0.38), for: .normal)
titleColor = theme.onSurface.withAlphaComponent(0.60)
}
/// This might be considered as a hackish way, but it's just manipulation
......
......@@ -31,7 +31,7 @@
import UIKit
import Motion
open class Button: UIButton, Pulseable, PulseableLayer {
open class Button: UIButton, Pulseable, PulseableLayer, Themeable {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
......@@ -281,7 +281,14 @@ open class Button: UIButton, Pulseable, PulseableLayer {
contentScaleFactor = Screen.scale
prepareVisualLayer()
preparePulse()
applyCurrentTheme()
}
/**
Applies given theme to the view.
- Parameter theme: A Theme.
*/
open func apply(theme: Theme) { }
}
extension Button {
......
......@@ -31,6 +31,12 @@ open class CheckButton: BaseIconLayerButton {
guard !isAnimating else { return }
setSelected(!isSelected, animated: true)
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
checkmarkColor = theme.onSecondary
}
}
internal class CheckBoxLayer: BaseIconLayer {
......@@ -86,6 +92,7 @@ internal class CheckBoxLayer: BaseIconLayer {
if isSelected {
borderLayer.borderWidth = borderLayerNormalBorderWidth
} else {
borderLayer.borderWidth = 0
borderLayer.backgroundColor = (isEnabled ? normalColor : disabledColor).cgColor
checkMarkLeftLayer.strokeEnd = 1
checkMarkRightLayer.strokeEnd = 1
......
......@@ -36,6 +36,14 @@ open class FABButton: Button {
depthPreset = .depth1
shapePreset = .circle
pulseAnimation = .centerWithBacking
backgroundColor = .white
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
backgroundColor = theme.secondary
titleColor = theme.onSecondary
tintColor = theme.onSecondary
pulseColor = theme.onSecondary
}
}
......@@ -35,4 +35,13 @@ open class FlatButton: Button {
super.prepare()
cornerRadiusPreset = .cornerRadius1
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
backgroundColor = .clear
titleColor = theme.secondary
tintColor = theme.secondary
pulseColor = theme.secondary
}
}
......@@ -35,4 +35,11 @@ open class IconButton: Button {
super.prepare()
pulseAnimation = .center
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
tintColor = theme.secondary
pulseColor = theme.secondary
}
}
......@@ -35,6 +35,14 @@ open class RaisedButton: Button {
super.prepare()
depthPreset = .depth1
cornerRadiusPreset = .cornerRadius1
backgroundColor = .white
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
backgroundColor = theme.secondary
titleColor = theme.onSecondary
pulseColor = theme.onSecondary
tintColor = theme.onSecondary
}
}
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