mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-01 18:33:10 +00:00
Support loading lottie animation from Data
This commit is contained in:
parent
fdef697932
commit
1be4f68269
@ -46,6 +46,35 @@ public final class AnimationNode : ASDisplayNode {
|
||||
})
|
||||
}
|
||||
|
||||
public init(animationData: Data, colors: [String: UIColor]? = nil, scale: CGFloat = 1.0) {
|
||||
self.scale = scale
|
||||
|
||||
super.init()
|
||||
|
||||
self.setViewBlock({
|
||||
if let json = try? JSONSerialization.jsonObject(with: animationData, options: []) as? [AnyHashable: Any] {
|
||||
let composition = LOTComposition(json: json)
|
||||
|
||||
let view = LOTAnimationView(model: composition, in: getAppBundle())
|
||||
view.animationSpeed = self.speed
|
||||
view.backgroundColor = .clear
|
||||
view.isOpaque = false
|
||||
|
||||
if let colors = colors {
|
||||
for (key, value) in colors {
|
||||
let colorCallback = LOTColorValueCallback(color: value.cgColor)
|
||||
self.colorCallbacks.append(colorCallback)
|
||||
view.setValueDelegate(colorCallback, for: LOTKeypath(string: "\(key).Color"))
|
||||
}
|
||||
}
|
||||
|
||||
return view
|
||||
} else {
|
||||
return LOTAnimationView()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public func setAnimation(name: String) {
|
||||
if let url = getAppBundle().url(forResource: name, withExtension: "json"), let composition = LOTComposition(filePath: url.path) {
|
||||
self.animationView()?.sceneModel = composition
|
||||
|
Loading…
x
Reference in New Issue
Block a user