Files
denlvovich e001d74afe Update to VGSL6.0
4f8b5f480ade3f347d5f0a2d01a1618069bcb846
2024-07-12 20:33:42 +03:00

61 lines
1.4 KiB
Swift

import UIKit
import LayoutKit
import VGSL
final class AnimationBlockView: BlockView {
var animatableView: AnimatableView? {
didSet {
if let animatablView = animatableView {
oldValue?.removeFrom(self)
addSubview(animatablView)
}
}
}
var animationContentMode: UIView.ContentMode = .scaleAspectFit {
didSet {
animatableView?.contentMode = animationContentMode
}
}
private var animationRequest: Cancellable?
var animationHolder: AnimationHolder? {
didSet {
animationRequest?.cancel()
let newValue = animationHolder
animationRequest = animationHolder?
.requestAnimationWithCompletion { [weak self] animationSource in
guard let self,
newValue === self.animationHolder,
let animationSource else {
return
}
self.animatableView?.contentMode = animationContentMode
self.animatableView?.setSource(animationSource)
self.animatableView?.play()
}
}
}
init() {
super.init(frame: .zero)
}
override func layoutSubviews() {
super.layoutSubviews()
animatableView?.frame = bounds
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let effectiveBackgroundColor: UIColor? = nil
}
extension AnimationBlockView: VisibleBoundsTrackingLeaf {}