Files
divkit/client/ios/DivKit/Animators/DivAnimatorController.swift
pkurchatov 32ca53c33d Applied swiftformat
commit_hash:9c5ecfc2fd0b9a8622daa639e908bceb6891d85c
2024-11-25 23:23:00 +03:00

70 lines
1.5 KiB
Swift

import Foundation
import LayoutKit
import VGSL
final class DivAnimatorController {
private var animators = [UIElementPath: Animator]()
private let lock = AllocatedUnfairLock()
func startAnimator(
path: UIElementPath,
id: String,
startValue: DivVariableValue?,
endValue: DivVariableValue?,
duration: Int?,
startDelay: Int?,
direction: AnimationDirection?,
progressInterpolator: ProgressInterpolator?,
repeatCount: RepeatCount?
) {
lock.withLock {
animators[path + id]?.start(
startValue: startValue,
endValue: endValue,
duration: duration,
startDelay: startDelay,
direction: direction,
progressInterpolator: progressInterpolator,
repeatCount: repeatCount
)
}
}
func stopAnimator(path: UIElementPath, id: String) {
lock.withLock {
animators[path + id]?.stop()
}
}
func initializeIfNeeded(path: UIElementPath, id: String, animator: Variable<Animator?>) {
lock.withLock {
guard animators[path + id] == nil, let animator = animator.value else { return }
animators[path + id] = animator
}
}
func reset() {
lock.withLock {
animators.values.forEach { $0.stop() }
animators.removeAll()
}
}
func reset(cardId: DivCardID) {
lock.withLock {
animators = animators.filter {
if $0.key.cardId == cardId {
$0.value.stop()
}
return $0.key.cardId != cardId
}
}
}
deinit {
lock.withLock {
animators.values.forEach { $0.stop() }
}
}
}