Storage improvements

This commit is contained in:
Ali
2022-12-24 00:04:48 +04:00
parent dd06922e85
commit 808f5b80ff
25 changed files with 3384 additions and 655 deletions

View File

@@ -765,4 +765,36 @@ public struct Transition {
}
}
}
public func setBackgroundColor(view: UIView, color: UIColor, completion: ((Bool) -> Void)? = nil) {
self.setBackgroundColor(layer: view.layer, color: color, completion: completion)
}
public func setBackgroundColor(layer: CALayer, color: UIColor, completion: ((Bool) -> Void)? = nil) {
if let current = layer.backgroundColor, current == color.cgColor {
completion?(true)
return
}
switch self.animation {
case .none:
layer.backgroundColor = color.cgColor
completion?(true)
case let .curve(duration, curve):
let previousColor: CGColor = layer.backgroundColor ?? UIColor.clear.cgColor
layer.backgroundColor = color.cgColor
layer.animate(
from: previousColor,
to: color.cgColor,
keyPath: "backgroundColor",
duration: duration,
delay: 0.0,
curve: curve,
removeOnCompletion: true,
additive: false,
completion: completion
)
}
}
}