mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Move code
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public final class ManagedAnimations {
|
||||
private var displayLinkSubscription: SharedDisplayLink.Subscription?
|
||||
|
||||
private var properties: [AnyAnimatedProperty] = []
|
||||
|
||||
public var updated: (() -> Void)?
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func add(property: AnyAnimatedProperty) {
|
||||
self.properties.append(property)
|
||||
property.didStartAnimation = { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.updateNeedAnimations()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateNeedAnimations() {
|
||||
if self.displayLinkSubscription == nil {
|
||||
self.displayLinkSubscription = SharedDisplayLink.shared.add { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func update() {
|
||||
var hasRunningAnimations = false
|
||||
for property in self.properties {
|
||||
property.update()
|
||||
if property.hasRunningAnimation {
|
||||
hasRunningAnimations = true
|
||||
}
|
||||
}
|
||||
|
||||
if !hasRunningAnimations {
|
||||
self.displayLinkSubscription = nil
|
||||
}
|
||||
|
||||
self.updated?()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user