Various fixes

This commit is contained in:
Ilya Laktyushin
2023-03-22 17:48:22 +04:00
parent 272f538060
commit 4018360cab
5 changed files with 49 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ import Foundation
import UIKit
import AsyncDisplayKit
import Lottie
import GZip
import AppBundle
import Display
@@ -32,7 +33,15 @@ public final class AnimationNode: ASDisplayNode {
super.init()
self.setViewBlock({
if let animationName = animationName, let url = getAppBundle().url(forResource: animationName, withExtension: "json"), let animation = Animation.filepath(url.path) {
var animation: Animation?
if let animationName {
if let url = getAppBundle().url(forResource: animationName, withExtension: "json"), let maybeAnimation = Animation.filepath(url.path) {
animation = maybeAnimation
} else if let url = getAppBundle().url(forResource: animationName, withExtension: "tgs"), let data = try? Data(contentsOf: URL(fileURLWithPath: url.path)), let unpackedData = TGGUnzipData(data, 5 * 1024 * 1024) {
animation = try? Animation.from(data: unpackedData, strategy: .codable)
}
}
if let animation {
let view = AnimationView(animation: animation, configuration: LottieConfiguration(renderingEngine: .mainThread, decodingStrategy: .codable))
view.animationSpeed = self.speed
view.backgroundColor = .clear
@@ -104,6 +113,10 @@ public final class AnimationNode: ASDisplayNode {
self.animationView()?.currentProgress = 1.0
}
public func setProgress(_ progress: CGFloat) {
self.animationView()?.currentProgress = progress
}
public func setAnimation(name: String, colors: [String: UIColor]? = nil) {
self.currentParams = (name, colors)
if let url = getAppBundle().url(forResource: name, withExtension: "json"), let animation = Animation.filepath(url.path) {