mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
2.0 KiB
Swift
49 lines
2.0 KiB
Swift
5 years ago
|
|
||
|
extension UIView {
|
||
|
|
||
|
struct CircularGlowConfiguration {
|
||
|
let size: CGFloat
|
||
|
let color: UIColor
|
||
|
let isAnimated: Bool
|
||
5 years ago
|
let animationDuration: TimeInterval
|
||
5 years ago
|
let offset: CGSize
|
||
|
let opacity: Float
|
||
|
let radius: CGFloat
|
||
|
|
||
5 years ago
|
init(size: CGFloat, color: UIColor, isAnimated: Bool = false, animationDuration: TimeInterval = 0.25, offset: CGSize = CGSize(width: 0, height: 0.8), opacity: Float = isLightMode ? 0.4 : 1, radius: CGFloat) {
|
||
5 years ago
|
self.size = size
|
||
|
self.color = color
|
||
|
self.isAnimated = isAnimated
|
||
5 years ago
|
self.animationDuration = animationDuration
|
||
5 years ago
|
self.offset = offset
|
||
|
self.opacity = opacity
|
||
|
self.radius = radius
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func setCircularGlow(with configuration: CircularGlowConfiguration) {
|
||
|
let newSize = configuration.size
|
||
|
let newPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint.zero, size: CGSize(width: newSize, height: newSize))).cgPath
|
||
|
if configuration.isAnimated {
|
||
|
let pathAnimation = CABasicAnimation(keyPath: "shadowPath")
|
||
|
pathAnimation.fromValue = layer.shadowPath
|
||
|
pathAnimation.toValue = newPath
|
||
5 years ago
|
pathAnimation.duration = configuration.animationDuration
|
||
5 years ago
|
layer.add(pathAnimation, forKey: pathAnimation.keyPath)
|
||
|
}
|
||
|
layer.shadowPath = newPath
|
||
|
let newColor = configuration.color.cgColor
|
||
|
if configuration.isAnimated {
|
||
|
let colorAnimation = CABasicAnimation(keyPath: "shadowColor")
|
||
|
colorAnimation.fromValue = layer.shadowColor
|
||
|
colorAnimation.toValue = newColor
|
||
5 years ago
|
colorAnimation.duration = configuration.animationDuration
|
||
5 years ago
|
layer.add(colorAnimation, forKey: colorAnimation.keyPath)
|
||
|
}
|
||
|
layer.shadowColor = newColor
|
||
|
layer.shadowOffset = configuration.offset
|
||
|
layer.shadowOpacity = configuration.opacity
|
||
|
layer.shadowRadius = configuration.radius
|
||
|
}
|
||
|
}
|