refactored dropshadow to use real code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
21d7ee8e45
commit
64b823da48
@ -353,7 +353,6 @@ public class ShadowView: View {
|
||||
|
||||
public var viewRadiusRange: CGFloat = 8.0 { didSet { setNeedsUpdate() }}
|
||||
|
||||
private var shadowLayer1: CALayer = CALayer()
|
||||
public var showShadow: Bool = true { didSet { setNeedsUpdate() }}
|
||||
public var opacityRange: CGFloat = 1.0 { didSet { setNeedsUpdate() }}
|
||||
public var offsetXRange: CGFloat = 2.0 { didSet { setNeedsUpdate() }}
|
||||
@ -362,7 +361,6 @@ public class ShadowView: View {
|
||||
public var shadowLightColor: UIColor.VDSColor = .backgroundPrimaryDark { didSet { setNeedsUpdate() }}
|
||||
public var shadowDarkColor: UIColor.VDSColor = .backgroundPrimaryLight { didSet { setNeedsUpdate() }}
|
||||
|
||||
private var shadowLayer2: CALayer = CALayer()
|
||||
public var showShadow2: Bool = false { didSet { setNeedsUpdate() }}
|
||||
public var opacityRange2: CGFloat = 1.0 { didSet { setNeedsUpdate() }}
|
||||
public var offsetXRange2: CGFloat = 2.0 { didSet { setNeedsUpdate() }}
|
||||
@ -376,46 +374,60 @@ public class ShadowView: View {
|
||||
width(constant: 100)
|
||||
height(constant: 100)
|
||||
|
||||
// Add shadow layers as sublayers of the view's layer
|
||||
layer.insertSublayer(shadowLayer1, at: 0)
|
||||
layer.insertSublayer(shadowLayer2, at: 0)
|
||||
}
|
||||
|
||||
public override func updateView() {
|
||||
super.updateView()
|
||||
let viewColor = SurfaceColorConfiguration(viewLightColor.uiColor, viewDarkColor.uiColor).getColor(surface)
|
||||
backgroundColor = viewColor
|
||||
shadowLayer1.backgroundColor = viewColor.cgColor
|
||||
shadowLayer2.backgroundColor = viewColor.cgColor
|
||||
shadowLayer1.isHidden = !showShadow
|
||||
shadowLayer2.isHidden = !showShadow2
|
||||
|
||||
setNeedsLayout()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
public override var backgroundColor: UIColor? {
|
||||
didSet {
|
||||
print("backgroundColor: \(backgroundColor?.hexString ?? "None")")
|
||||
}
|
||||
}
|
||||
|
||||
public override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
layer.cornerRadius = CGFloat(viewRadiusRange)
|
||||
|
||||
let dropshadowColor = SurfaceColorConfiguration(shadowLightColor.uiColor, shadowDarkColor.uiColor).getColor(surface)
|
||||
let dropshadowColor2 = SurfaceColorConfiguration(shadowLightColor2.uiColor, shadowDarkColor2.uiColor).getColor(surface)
|
||||
layer.cornerRadius = CGFloat(viewRadiusRange)
|
||||
layer.masksToBounds = false
|
||||
var shadowConfigs = [DropShadowConfiguration]()
|
||||
|
||||
// Update shadow layers frames to match the view's bounds
|
||||
shadowLayer1.frame = bounds
|
||||
shadowLayer2.frame = bounds
|
||||
|
||||
shadowLayer1.cornerRadius = CGFloat(viewRadiusRange)
|
||||
shadowLayer1.shadowColor = dropshadowColor.cgColor
|
||||
shadowLayer1.shadowOpacity = Float(opacityRange)
|
||||
shadowLayer1.shadowOffset = .init(width: CGFloat(offsetXRange), height: CGFloat(offsetYRange))
|
||||
shadowLayer1.shadowRadius = CGFloat(radiusRange)
|
||||
if showShadow {
|
||||
let shadow1Config = VDS.DropShadowConfiguration().with {
|
||||
$0.shadowRadiusConfiguration = .init(viewRadiusRange, .zero)
|
||||
$0.shadowColorConfiguration = SurfaceColorConfiguration(dropshadowColor, dropshadowColor).eraseToAnyColorable()
|
||||
$0.shadowOpacityConfiguration = .init(opacityRange, .zero)
|
||||
$0.shadowOffsetConfiguration = .init(.init(width: offsetXRange, height: offsetYRange), .zero)
|
||||
$0.shadowRadiusConfiguration = .init(radiusRange, .zero)
|
||||
}
|
||||
shadowConfigs.append(shadow1Config)
|
||||
}
|
||||
|
||||
shadowLayer2.cornerRadius = CGFloat(viewRadiusRange)
|
||||
shadowLayer2.shadowColor = dropshadowColor2.cgColor
|
||||
shadowLayer2.shadowOpacity = Float(opacityRange2)
|
||||
shadowLayer2.shadowOffset = .init(width: CGFloat(offsetXRange2), height: CGFloat(offsetYRange2))
|
||||
shadowLayer2.shadowRadius = CGFloat(radiusRange2)
|
||||
if showShadow2 {
|
||||
let shadow2Config = VDS.DropShadowConfiguration().with {
|
||||
$0.shadowRadiusConfiguration = .init(viewRadiusRange, .zero)
|
||||
$0.shadowColorConfiguration = SurfaceColorConfiguration(dropshadowColor2, dropshadowColor2).eraseToAnyColorable()
|
||||
$0.shadowOpacityConfiguration = .init(opacityRange2, .zero)
|
||||
$0.shadowOffsetConfiguration = .init(.init(width: offsetXRange2, height: offsetYRange2), .zero)
|
||||
$0.shadowRadiusConfiguration = .init(radiusRange2, .zero)
|
||||
}
|
||||
shadowConfigs.append(shadow2Config)
|
||||
}
|
||||
|
||||
if shadowConfigs.count > 0 {
|
||||
addDropShadows(shadowConfigs)
|
||||
} else {
|
||||
removeDropShadows()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user