mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
41 lines
1.0 KiB
Swift
41 lines
1.0 KiB
Swift
import DivKit
|
|
import DivKitExtensions
|
|
import Foundation
|
|
import LayoutKit
|
|
import RiveRuntime
|
|
import VGSL
|
|
|
|
final class RiveAnimationFactory: DivCustomBlockFactory {
|
|
private let requester: URLResourceRequesting
|
|
|
|
init(requester: URLResourceRequesting) {
|
|
self.requester = requester
|
|
}
|
|
|
|
func makeBlock(data: DivCustomData, context _: DivBlockModelingContext) -> Block {
|
|
do {
|
|
let riveData = try data.toRiveDivCustomData()
|
|
let animationHolder = RemoteAnimationHolder(
|
|
url: riveData.url,
|
|
animationType: .rive,
|
|
requester: requester,
|
|
localDataProvider: nil
|
|
)
|
|
|
|
return RiveAnimationBlock(
|
|
animationHolder: animationHolder,
|
|
animatableView: Lazy(value: RiveContainerView(
|
|
fit: riveData.fit,
|
|
alignment: riveData.alignment,
|
|
loop: riveData.loop
|
|
)),
|
|
widthTrait: data.widthTrait,
|
|
heightTrait: data.heightTrait
|
|
)
|
|
} catch {
|
|
assertionFailure("Failed to make block with RiveAnimationFactory")
|
|
return SeparatorBlock()
|
|
}
|
|
}
|
|
}
|