mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[WIP] Video chat v2
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user