From d7bacbbb10d5ba7c5e942142c0f06cf2ac2cd7e8 Mon Sep 17 00:00:00 2001 From: denlvovich Date: Tue, 25 Feb 2025 00:26:25 +0300 Subject: [PATCH] Transition animations fix commit_hash:90807f6239d347328fb542b26569746855223d71 --- ...AnimationBlock+UIViewRenderableBlock.swift | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/client/ios/LayoutKit/LayoutKit/UI/Blocks/DetachableAnimationBlock+UIViewRenderableBlock.swift b/client/ios/LayoutKit/LayoutKit/UI/Blocks/DetachableAnimationBlock+UIViewRenderableBlock.swift index d0178e097..3de1e58b8 100644 --- a/client/ios/LayoutKit/LayoutKit/UI/Blocks/DetachableAnimationBlock+UIViewRenderableBlock.swift +++ b/client/ios/LayoutKit/LayoutKit/UI/Blocks/DetachableAnimationBlock+UIViewRenderableBlock.swift @@ -67,6 +67,7 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView private var animationChange: ChangeBoundsTransition? private var queuedAnimation: DispatchWorkItem? private var child: Block? + private var isFirstLayout: Bool = true var effectiveBackgroundColor: UIColor? { childView?.effectiveBackgroundColor } @@ -90,13 +91,20 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView self.animationIn = animationIn self.animationOut = animationOut self.animationChange = animationChange + setNeedsLayout() } override func layoutSubviews() { super.layoutSubviews() + guard isFirstLayout || animationChange == nil else { + return + } childView?.frame = bounds + if frame != .zero { + isFirstLayout = false + } } public var hasAnimationIn: Bool { @@ -122,13 +130,6 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView self.childView = nil - let blockSize = CGSize( - width: startFrame.width, - height: child?.intrinsicContentHeight(forWidth: startFrame.width) ?? .zero - ) - childView.frame.size = blockSize - childView.layoutIfNeeded() - let animationContainer = UIView() animationContainer.frame = startFrame animationContainer.clipsToBounds = false @@ -143,14 +144,12 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView options: [animationChange.timingFunction.cast()], animations: { animationContainer.frame = finishFrame - childView.frame.size = CGSize( - width: finishFrame.width, - height: self.child?.intrinsicContentHeight(forWidth: finishFrame.width) ?? .zero - ) + childView.frame.size = animationContainer.bounds.size childView.layoutIfNeeded() container.layoutIfNeeded() }, completion: { [weak self] _ in + self?.animationChange = nil if animationContainer.superview == container { animationContainer.removeFromSuperview() self?.childView = childView @@ -167,8 +166,9 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView childView.frame = convertFrame(to: container) self.childView = nil container.addSubview(childView) - childView.perform(animationOut, animated: true, completion: { + childView.perform(animationOut, animated: true, completion: { [weak self] in childView.removeFromSuperview() + self?.animationOut = nil }) } @@ -192,6 +192,7 @@ final class DetachableAnimationBlockView: BlockView, DelayedVisibilityActionView completion: { [weak self] in self?.queuedAnimation = nil + self?.animationIn = nil if childView.superview == container { childView.frame = originalFrame self?.childView = childView