@@ -42,16 +42,46 @@ public final class DotLottieFile {
42
42
private( set) var imageProvider : DotLottieImageProvider ?
43
43
44
44
/// Animations folder url
45
- lazy var animationsUrl : URL = fileUrl. appendingPathComponent ( " \( DotLottieFile . animationsFolderName) " )
45
+ ///
46
+ /// - Parameters:
47
+ /// - version: version of .lottie file
48
+ func animationsUrl( for version: String ? ) -> URL {
49
+ switch Int ( version ?? " 1 " ) ?? 1 {
50
+ case 2 ... :
51
+ fileUrl. appendingPathComponent ( " a " )
52
+ default :
53
+ fileUrl. appendingPathComponent ( " animations " )
54
+ }
55
+ }
46
56
47
57
/// All files in animations folder
48
- lazy var animationUrls : [ URL ] = FileManager . default. urls ( for: animationsUrl) ?? [ ]
58
+ ///
59
+ /// - Parameters:
60
+ /// - version: version of .lottie file
61
+ func animationUrls( for version: String ? ) -> [ URL ] {
62
+ FileManager . default. urls ( for: animationsUrl ( for: version) ) ?? [ ]
63
+ }
49
64
50
65
/// Images folder url
51
- lazy var imagesUrl : URL = fileUrl. appendingPathComponent ( " \( DotLottieFile . imagesFolderName) " )
66
+ ///
67
+ /// - Parameters:
68
+ /// - version: version of .lottie file
69
+ func imagesUrl( for version: String ? ) -> URL {
70
+ switch Int ( version ?? " 1 " ) ?? 1 {
71
+ case 2 ... :
72
+ fileUrl. appendingPathComponent ( " i " )
73
+ default :
74
+ fileUrl. appendingPathComponent ( " images " )
75
+ }
76
+ }
52
77
53
78
/// All images in images folder
54
- lazy var imageUrls : [ URL ] = FileManager . default. urls ( for: imagesUrl) ?? [ ]
79
+ ///
80
+ /// - Parameters:
81
+ /// - version: version of .lottie file
82
+ func imageUrls( for version: String ? ) -> [ URL ] {
83
+ FileManager . default. urls ( for: imagesUrl ( for: version) ) ?? [ ]
84
+ }
55
85
56
86
/// The `LottieAnimation` and `DotLottieConfiguration` for the given animation ID in this file
57
87
func animation( for id: String ? = nil ) -> DotLottieFile . Animation ? {
@@ -71,8 +101,6 @@ public final class DotLottieFile {
71
101
// MARK: Private
72
102
73
103
private static let manifestFileName = " manifest.json "
74
- private static let animationsFolderName = " animations "
75
- private static let imagesFolderName = " images "
76
104
77
105
private let fileUrl : URL
78
106
@@ -104,10 +132,12 @@ public final class DotLottieFile {
104
132
105
133
/// Loads file content to memory
106
134
private func loadContent( ) throws {
107
- imageProvider = DotLottieImageProvider ( filepath: imagesUrl)
135
+ let manifest = try loadManifest ( )
136
+
137
+ imageProvider = DotLottieImageProvider ( filepath: imagesUrl ( for: manifest. version) )
108
138
109
- animations = try loadManifest ( ) . animations. map { dotLottieAnimation in
110
- let animation = try dotLottieAnimation. animation ( url: animationsUrl)
139
+ animations = try manifest . animations. map { dotLottieAnimation in
140
+ let animation = try dotLottieAnimation. animation ( url: animationsUrl ( for : manifest . version ) )
111
141
let configuration = DotLottieConfiguration (
112
142
id: dotLottieAnimation. id,
113
143
loopMode: dotLottieAnimation. loopMode,
0 commit comments