From 53ddac7c142824e3bc375d49274b0b296b289cca Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 18 May 2023 03:08:05 +0400 Subject: [PATCH] Fix managed animation frame advancement --- .../Sources/ManagedAnimationNode.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift b/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift index 914f8c2279..2343704a2b 100644 --- a/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift +++ b/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift @@ -190,13 +190,18 @@ open class ManagedAnimationNode: ASDisplayNode { self.addSubnode(self.imageNode) - var previousTimestamp = CACurrentMediaTime() displayLinkUpdate = { [weak self] in if let strongSelf = self { let currentTimestamp = CACurrentMediaTime() - strongSelf.delta = currentTimestamp - previousTimestamp + let delta: Double + if let previousTimestamp = strongSelf.previousTimestamp { + delta = currentTimestamp - previousTimestamp + } else { + delta = 1.0 / 60.0 + } + strongSelf.delta = delta strongSelf.updateAnimation() - previousTimestamp = currentTimestamp + strongSelf.previousTimestamp = currentTimestamp } } } @@ -216,6 +221,7 @@ open class ManagedAnimationNode: ASDisplayNode { } self.didTryAdvancingState = false + self.previousTimestamp = CACurrentMediaTime() self.displayLink.isPaused = false }