Commit b5908d83 by Orkhan Alikhanov

Made buttons themeable

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