Fix video chat action button tint transition

This commit is contained in:
Isaac 2024-09-25 01:26:17 +08:00
parent 3d509c7bda
commit b712754820
2 changed files with 26 additions and 1 deletions

View File

@ -1189,6 +1189,27 @@ public struct ComponentTransition {
} }
} }
public func animateTintColor(layer: CALayer, from: UIColor, to: UIColor, completion: ((Bool) -> Void)? = nil) {
switch self.animation {
case .none:
completion?(true)
case let .curve(duration, curve):
let previousColor: CGColor = from.cgColor
layer.animate(
from: previousColor,
to: to.cgColor,
keyPath: "contentsMultiplyColor",
duration: duration,
delay: 0.0,
curve: curve,
removeOnCompletion: true,
additive: false,
completion: completion
)
}
}
public func setGradientColors(layer: CAGradientLayer, colors: [UIColor], completion: ((Bool) -> Void)? = nil) { public func setGradientColors(layer: CAGradientLayer, colors: [UIColor], completion: ((Bool) -> Void)? = nil) {
if let current = layer.colors { if let current = layer.colors {
if current.count == colors.count { if current.count == colors.count {

View File

@ -267,7 +267,11 @@ final class VideoChatActionButtonComponent: Component {
} else { } else {
tintTransition = .immediate tintTransition = .immediate
} }
tintTransition.setTintColor(layer: self.background.layer, color: backgroundColor) let previousTintColor = self.background.tintColor
self.background.tintColor = backgroundColor
if let previousTintColor, previousTintColor != backgroundColor {
tintTransition.animateTintColor(layer: self.background.layer, from: previousTintColor, to: backgroundColor)
}
let titleFrame = CGRect(origin: CGPoint(x: floor((size.width - titleSize.width) * 0.5), y: size.height + 8.0), size: titleSize) let titleFrame = CGRect(origin: CGPoint(x: floor((size.width - titleSize.width) * 0.5), y: size.height + 8.0), size: titleSize)
if let titleView = self.title.view { if let titleView = self.title.view {