refactored dropshadow
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
86f7701c2e
commit
d7cad33727
@ -172,13 +172,13 @@ open class ButtonIcon: Control {
|
||||
SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, .clear).eraseToAnyColorable()
|
||||
}()
|
||||
var shadowColorConfiguration: AnyColorable = {
|
||||
SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, .clear).eraseToAnyColorable()
|
||||
SurfaceColorConfiguration(VDSColor.paletteBlack, .clear).eraseToAnyColorable()
|
||||
}()
|
||||
var shadowOpacity: CGFloat = 0.5
|
||||
var shadowOffset: CGSize = .init(width: 1, height: 1)
|
||||
var shadowOpacity: CGFloat = 0.16
|
||||
var shadowOffset: CGSize = .init(width: 0, height: 2)
|
||||
var shadowRadius: CGFloat = 2
|
||||
}
|
||||
|
||||
|
||||
private struct HighContrastConfiguration: Configuration {
|
||||
var kind: Kind = .highContrast
|
||||
var surfaceType: SurfaceType = .colorFill
|
||||
@ -280,7 +280,6 @@ open class ButtonIcon: Control {
|
||||
} else {
|
||||
icon.reset()
|
||||
}
|
||||
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
@ -316,26 +315,15 @@ open class ButtonIcon: Control {
|
||||
if let borderable = currentConfig as? Borderable {
|
||||
layer.borderColor = borderable.borderColorConfiguration.getColor(self).cgColor
|
||||
layer.borderWidth = borderable.borderWidth
|
||||
icon.layer.borderWidth = borderable.borderWidth
|
||||
} else {
|
||||
layer.borderColor = nil
|
||||
layer.borderWidth = 0
|
||||
icon.layer.borderWidth = 0
|
||||
}
|
||||
|
||||
if let dropshadowable = currentConfig as? Dropshadowable {
|
||||
layer.masksToBounds = false
|
||||
layer.shadowColor = dropshadowable.shadowColorConfiguration.getColor(self).cgColor
|
||||
layer.shadowOpacity = Float(dropshadowable.shadowOpacity)
|
||||
layer.shadowOffset = dropshadowable.shadowOffset
|
||||
layer.shadowRadius = dropshadowable.shadowRadius
|
||||
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
|
||||
layer.shouldRasterize = true
|
||||
layer.rasterizationScale = UIScreen.main.scale
|
||||
addDropShadow(config: dropshadowable)
|
||||
} else {
|
||||
layer.shadowOpacity = 0
|
||||
layer.shadowRadius = 0
|
||||
layer.shadowPath = nil
|
||||
removeDropShadow()
|
||||
}
|
||||
|
||||
}
|
||||
@ -360,6 +348,25 @@ extension ButtonIcon: AppleGuidlinesTouchable {
|
||||
|
||||
}
|
||||
|
||||
extension UIView {
|
||||
fileprivate func addDropShadow(config: Dropshadowable) {
|
||||
layer.masksToBounds = false
|
||||
layer.shadowColor = config.shadowColorConfiguration.getColor(self).cgColor
|
||||
layer.shadowOpacity = Float(config.shadowOpacity)
|
||||
layer.shadowOffset = config.shadowOffset
|
||||
layer.shadowRadius = config.shadowRadius
|
||||
layer.shouldRasterize = true
|
||||
layer.rasterizationScale = UIScreen.main.scale
|
||||
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: layer.cornerRadius).cgPath
|
||||
}
|
||||
|
||||
fileprivate func removeDropShadow() {
|
||||
layer.shadowOpacity = 0
|
||||
layer.shadowRadius = 0
|
||||
layer.shadowPath = nil
|
||||
}
|
||||
}
|
||||
|
||||
private protocol Borderable {
|
||||
var borderWidth: CGFloat { get set }
|
||||
var borderColorConfiguration: AnyColorable { get set }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user