mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Transition animations fix
commit_hash:90807f6239d347328fb542b26569746855223d71
This commit is contained in:
+13
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user