Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions Example/Example/AnimationListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ struct AnimationListView: View {
var body: some View {
List {
ForEach(items, id: \.self) { item in
NavigationLink(value: item) {
NavigationLink {
switch item {
case .animation(_, let animationPath):
AnimationPreviewView(animationSource: .local(animationPath: animationPath))
case .remoteAnimations(let name, let urls):
AnimationPreviewView(animationSource: .remote(urls: urls, name: name))
case .animationList(let listContent):
AnimationListView(content: listContent)
case .controlsDemo:
ControlsDemoView()
case .swiftUIInteroperability:
SwiftUIInteroperabilityDemoView()
case .lottieViewLayoutDemo:
LottieViewLayoutDemoView()
}
} label: {
switch item {
case .animation, .remoteAnimations:
HStack {
Expand All @@ -40,22 +55,6 @@ struct AnimationListView: View {
.frame(height: 50)
}
}
.navigationDestination(for: Item.self) { item in
switch item {
case .animation(_, let animationPath):
AnimationPreviewView(animationSource: .local(animationPath: animationPath))
case .remoteAnimations(let name, let urls):
AnimationPreviewView(animationSource: .remote(urls: urls, name: name))
case .animationList(let listContent):
AnimationListView(content: listContent)
case .controlsDemo:
ControlsDemoView()
case .swiftUIInteroperability:
SwiftUIInteroperabilityDemoView()
case .lottieViewLayoutDemo:
LottieViewLayoutDemoView()
}
}
}
}
.navigationTitle(content.name)
Expand Down
48 changes: 39 additions & 9 deletions Sources/Public/DotLottie/DotLottieFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,46 @@ public final class DotLottieFile {
private(set) var imageProvider: DotLottieImageProvider?

/// Animations folder url
lazy var animationsUrl: URL = fileUrl.appendingPathComponent("\(DotLottieFile.animationsFolderName)")
///
/// - Parameters:
/// - version: version of .lottie file
func animationsUrl(for version: String?) -> URL {
switch Int(version ?? "1") ?? 1 {
case 2...:
fileUrl.appendingPathComponent("a")
default:
fileUrl.appendingPathComponent("animations")
}
}

/// All files in animations folder
lazy var animationUrls: [URL] = FileManager.default.urls(for: animationsUrl) ?? []
///
/// - Parameters:
/// - version: version of .lottie file
func animationUrls(for version: String?) -> [URL] {
FileManager.default.urls(for: animationsUrl(for: version)) ?? []
}

/// Images folder url
lazy var imagesUrl: URL = fileUrl.appendingPathComponent("\(DotLottieFile.imagesFolderName)")
///
/// - Parameters:
/// - version: version of .lottie file
func imagesUrl(for version: String?) -> URL {
switch Int(version ?? "1") ?? 1 {
case 2...:
fileUrl.appendingPathComponent("i")
default:
fileUrl.appendingPathComponent("images")
}
}

/// All images in images folder
lazy var imageUrls: [URL] = FileManager.default.urls(for: imagesUrl) ?? []
///
/// - Parameters:
/// - version: version of .lottie file
func imageUrls(for version: String?) -> [URL] {
FileManager.default.urls(for: imagesUrl(for: version)) ?? []
}

/// The `LottieAnimation` and `DotLottieConfiguration` for the given animation ID in this file
func animation(for id: String? = nil) -> DotLottieFile.Animation? {
Expand All @@ -71,8 +101,6 @@ public final class DotLottieFile {
// MARK: Private

private static let manifestFileName = "manifest.json"
private static let animationsFolderName = "animations"
private static let imagesFolderName = "images"

private let fileUrl: URL

Expand Down Expand Up @@ -104,10 +132,12 @@ public final class DotLottieFile {

/// Loads file content to memory
private func loadContent() throws {
imageProvider = DotLottieImageProvider(filepath: imagesUrl)
let manifest = try loadManifest()

imageProvider = DotLottieImageProvider(filepath: imagesUrl(for: manifest.version))

animations = try loadManifest().animations.map { dotLottieAnimation in
let animation = try dotLottieAnimation.animation(url: animationsUrl)
animations = try manifest.animations.map { dotLottieAnimation in
let animation = try dotLottieAnimation.animation(url: animationsUrl(for: manifest.version))
let configuration = DotLottieConfiguration(
id: dotLottieAnimation.id,
loopMode: dotLottieAnimation.loopMode,
Expand Down
Binary file added Tests/Samples/DotLottie/zen_lottiev2.lottie
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Supports Core Animation engine
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading