refactored dropshadow

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-14 08:17:42 -05:00
parent 86f7701c2e
commit d7cad33727

View File

@ -172,13 +172,13 @@ open class ButtonIcon: Control {
SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, .clear).eraseToAnyColorable() SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, .clear).eraseToAnyColorable()
}() }()
var shadowColorConfiguration: AnyColorable = { var shadowColorConfiguration: AnyColorable = {
SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, .clear).eraseToAnyColorable() SurfaceColorConfiguration(VDSColor.paletteBlack, .clear).eraseToAnyColorable()
}() }()
var shadowOpacity: CGFloat = 0.5 var shadowOpacity: CGFloat = 0.16
var shadowOffset: CGSize = .init(width: 1, height: 1) var shadowOffset: CGSize = .init(width: 0, height: 2)
var shadowRadius: CGFloat = 2 var shadowRadius: CGFloat = 2
} }
private struct HighContrastConfiguration: Configuration { private struct HighContrastConfiguration: Configuration {
var kind: Kind = .highContrast var kind: Kind = .highContrast
var surfaceType: SurfaceType = .colorFill var surfaceType: SurfaceType = .colorFill
@ -280,7 +280,6 @@ open class ButtonIcon: Control {
} else { } else {
icon.reset() icon.reset()
} }
setNeedsLayout() setNeedsLayout()
} }
@ -316,26 +315,15 @@ open class ButtonIcon: Control {
if let borderable = currentConfig as? Borderable { if let borderable = currentConfig as? Borderable {
layer.borderColor = borderable.borderColorConfiguration.getColor(self).cgColor layer.borderColor = borderable.borderColorConfiguration.getColor(self).cgColor
layer.borderWidth = borderable.borderWidth layer.borderWidth = borderable.borderWidth
icon.layer.borderWidth = borderable.borderWidth
} else { } else {
layer.borderColor = nil layer.borderColor = nil
layer.borderWidth = 0 layer.borderWidth = 0
icon.layer.borderWidth = 0
} }
if let dropshadowable = currentConfig as? Dropshadowable { if let dropshadowable = currentConfig as? Dropshadowable {
layer.masksToBounds = false addDropShadow(config: dropshadowable)
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
} else { } else {
layer.shadowOpacity = 0 removeDropShadow()
layer.shadowRadius = 0
layer.shadowPath = nil
} }
} }
@ -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 { private protocol Borderable {
var borderWidth: CGFloat { get set } var borderWidth: CGFloat { get set }
var borderColorConfiguration: AnyColorable { get set } var borderColorConfiguration: AnyColorable { get set }