[WIP] Video chat v2

This commit is contained in:
Isaac
2024-09-03 22:34:04 +08:00
parent 53cb586691
commit d2b4622ef0
14 changed files with 1544 additions and 165 deletions

View File

@@ -17,7 +17,7 @@ public extension UIView {
}
private extension CALayer {
func animate(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double, curve: ComponentTransition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) {
func animate(from: Any, to: Any, keyPath: String, duration: Double, delay: Double, curve: ComponentTransition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) {
let timingFunction: String
let mediaTimingFunction: CAMediaTimingFunction?
switch curve {
@@ -1184,6 +1184,44 @@ public struct ComponentTransition {
}
}
public func setGradientColors(layer: CAGradientLayer, colors: [UIColor], completion: ((Bool) -> Void)? = nil) {
if let current = layer.colors {
if current.count == colors.count {
let currentColors = current.map { UIColor(cgColor: $0 as! CGColor) }
if currentColors == colors {
completion?(true)
return
}
}
}
switch self.animation {
case .none:
layer.colors = colors.map(\.cgColor)
completion?(true)
case let .curve(duration, curve):
let previousColors: [Any]
if let current = layer.colors {
previousColors = current
} else {
previousColors = (0 ..< colors.count).map { _ in UIColor.clear.cgColor as Any }
}
layer.colors = colors.map(\.cgColor)
layer.animate(
from: previousColors,
to: colors.map(\.cgColor),
keyPath: "colors",
duration: duration,
delay: 0.0,
curve: curve,
removeOnCompletion: true,
additive: false,
completion: completion
)
}
}
public func animateContentsImage(layer: CALayer, from fromImage: CGImage, to toImage: CGImage, duration: Double, curve: ComponentTransition.Animation.Curve, completion: ((Bool) -> Void)? = nil) {
layer.animate(
from: fromImage,