Skip to content

Commit

Permalink
Also improve AnimationPreviewView
Browse files Browse the repository at this point in the history
  • Loading branch information
calda committed Aug 3, 2023
1 parent 1727b28 commit 6487e56
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Example/Example/AnimationPreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct AnimationPreviewView: View {
var body: some View {
VStack {
LottieView {
try await lottieSource()
try await loadAnimation()
} placeholder: {
LoadingIndicator()
.frame(width: 50, height: 50)
Expand Down Expand Up @@ -86,18 +86,17 @@ struct AnimationPreviewView: View {
@State private var sliderValue: AnimationProgressTime = 0
@State private var currentURLIndex: Int

private func lottieSource() async throws -> LottieAnimationSource? {
private func loadAnimation() async throws -> LottieAnimationSource? {
switch animationSource {
case .local(let name):
if let animation = LottieAnimation.named(name) {
return .lottieAnimation(animation)
if name.hasSuffix(".lottie") {
return try await DotLottieFile.named(name).animationSource
} else {
let lottie = try await DotLottieFile.named(name)
return .dotLottieFile(lottie)
return LottieAnimation.named(name)?.animationSource
}

case .remote:
let animation = await LottieAnimation.loadedFrom(url: urls[currentURLIndex])
return animation.map(LottieAnimationSource.lottieAnimation)
return await LottieAnimation.loadedFrom(url: urls[currentURLIndex])?.animationSource
}
}

Expand Down

0 comments on commit 6487e56

Please sign in to comment.