From b71275482055b2b59ab41da9080fde4a843f98c3 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Wed, 25 Sep 2024 01:26:17 +0800 Subject: [PATCH] Fix video chat action button tint transition --- .../Source/Base/Transition.swift | 21 +++++++++++++++++++ .../VideoChatActionButtonComponent.swift | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/submodules/ComponentFlow/Source/Base/Transition.swift b/submodules/ComponentFlow/Source/Base/Transition.swift index b42f21063e..837eacb44d 100644 --- a/submodules/ComponentFlow/Source/Base/Transition.swift +++ b/submodules/ComponentFlow/Source/Base/Transition.swift @@ -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) { if let current = layer.colors { if current.count == colors.count { diff --git a/submodules/TelegramCallsUI/Sources/VideoChatActionButtonComponent.swift b/submodules/TelegramCallsUI/Sources/VideoChatActionButtonComponent.swift index 435bdecdaf..e965986f30 100644 --- a/submodules/TelegramCallsUI/Sources/VideoChatActionButtonComponent.swift +++ b/submodules/TelegramCallsUI/Sources/VideoChatActionButtonComponent.swift @@ -267,7 +267,11 @@ final class VideoChatActionButtonComponent: Component { } else { 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) if let titleView = self.title.view {