mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
0663870bf9
commit_hash:52ce6e4a9f35a44ddef28565cec76ddaabdc2d08
79 lines
1.7 KiB
Swift
79 lines
1.7 KiB
Swift
#if os(iOS)
|
|
import LayoutKit
|
|
import UIKit
|
|
import VGSL
|
|
|
|
final class AnimationBlockView: BlockView {
|
|
var animatableView: AsyncSourceAnimatableView? {
|
|
didSet {
|
|
if let animatablView = animatableView {
|
|
oldValue?.removeFrom(self)
|
|
addSubview(animatablView)
|
|
}
|
|
}
|
|
}
|
|
|
|
var animationContentMode: UIView.ContentMode = .scaleAspectFit {
|
|
didSet {
|
|
animatableView?.contentMode = animationContentMode
|
|
}
|
|
}
|
|
|
|
var isPlaying: Bool = true {
|
|
didSet {
|
|
guard oldValue != isPlaying else { return }
|
|
if isPlaying {
|
|
animatableView?.play()
|
|
} else {
|
|
animatableView?.pause()
|
|
}
|
|
}
|
|
}
|
|
|
|
var animationHolder: AnimationHolder? {
|
|
didSet {
|
|
animationRequest?.cancel()
|
|
|
|
let newValue = animationHolder
|
|
animationRequest = animationHolder?
|
|
.requestAnimationWithCompletion { [weak self] animationSource in
|
|
guard let self,
|
|
newValue === self.animationHolder,
|
|
let animationSource,
|
|
let view = self.animatableView else {
|
|
return
|
|
}
|
|
|
|
view.contentMode = animationContentMode
|
|
Task { @MainActor in
|
|
await view.setSourceAsync(animationSource)
|
|
if self.isPlaying {
|
|
view.play()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
let effectiveBackgroundColor: UIColor? = nil
|
|
|
|
private var animationRequest: Cancellable?
|
|
|
|
init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder _: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
animatableView?.frame = bounds
|
|
}
|
|
}
|
|
|
|
extension AnimationBlockView: VisibleBoundsTrackingLeaf {}
|
|
#endif
|