From 68986f9e5bd39b0de09538d64df2762d2402baaa Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 20 Nov 2021 17:58:30 +0400 Subject: [PATCH] Fix spring animation --- submodules/ContextUI/Sources/ContextController.swift | 9 +++++---- submodules/Display/Source/CAAnimationUtils.swift | 4 ++-- .../Sources/ReactionContextNode.swift | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index ea74e730f7..ec062da935 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -1135,6 +1135,11 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } self.reactionContextNodeIsAnimatingOut = true + reactionContextNode.willAnimateOutToReaction(value: value) + self.animateOut(result: .default, completion: { + contentCompleted = true + intermediateCompletion() + }) reactionContextNode.animateOutToReaction(value: value, targetEmptyNode: targetEmptyNode, targetFilledNode: targetFilledNode, hideNode: hideNode, completion: { [weak self] in guard let strongSelf = self else { return @@ -1144,10 +1149,6 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi reactionCompleted = true intermediateCompletion() }) - self.animateOut(result: .default, completion: { - contentCompleted = true - intermediateCompletion() - }) self.isUserInteractionEnabled = false } diff --git a/submodules/Display/Source/CAAnimationUtils.swift b/submodules/Display/Source/CAAnimationUtils.swift index 9c51d016d1..5fc052945d 100644 --- a/submodules/Display/Source/CAAnimationUtils.swift +++ b/submodules/Display/Source/CAAnimationUtils.swift @@ -151,7 +151,7 @@ public extension CALayer { let animationGroup = CAAnimationGroup() var timeOffset = 0.0 for animation in animations { - animation.beginTime = animation.beginTime + timeOffset + animation.beginTime = self.convertTime(animation.beginTime, from: nil) + timeOffset timeOffset += animation.duration / Double(animation.speed) } animationGroup.animations = animations @@ -217,7 +217,7 @@ public extension CALayer { } if !delay.isZero { - animation.beginTime = CACurrentMediaTime() + delay * UIView.animationDurationFactor() + animation.beginTime = self.convertTime(CACurrentMediaTime(), from: nil) + delay * UIView.animationDurationFactor() animation.fillMode = .both } diff --git a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift index 9f59509492..2b2a94536f 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift @@ -528,6 +528,15 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate { itemNode.layer.animateScale(from: 1.0, to: (targetSnapshotView.bounds.width * 0.5) / itemNode.bounds.width, duration: duration, removeOnCompletion: false) } + public func willAnimateOutToReaction(value: String) { + for itemNode in self.itemNodes { + if itemNode.item.reaction.rawValue != value { + continue + } + itemNode.isExtracted = true + } + } + public func animateOutToReaction(value: String, targetEmptyNode: ASDisplayNode, targetFilledNode: ASDisplayNode, hideNode: Bool, completion: @escaping () -> Void) { for itemNode in self.itemNodes { if itemNode.item.reaction.rawValue != value {