Skip to content

Commit

Permalink
Merge pull request #8 from teufelaudio/lottie-animation-progress-envi…
Browse files Browse the repository at this point in the history
…ronment-key

Added new environment key to be able to change the animation progress
  • Loading branch information
GiuliaAriu committed Sep 15, 2022
2 parents c6d6793 + 4a66046 commit cfb104c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
@@ -0,0 +1,14 @@
// Copyright © 2022 Lautsprecher Teufel GmbH. All rights reserved.

import SwiftUI

extension EnvironmentValues {
var lottieAnimationProgress: CGFloat {
get { return self[LottieAnimationProgressEnvironmentKey.self] }
set { self[LottieAnimationProgressEnvironmentKey.self] = newValue }
}
}

public struct LottieAnimationProgressEnvironmentKey: EnvironmentKey {
public static let defaultValue: CGFloat = 0.5
}
3 changes: 2 additions & 1 deletion Sources/LottieExtensions/LottieView.swift
Expand Up @@ -17,6 +17,7 @@ public struct LottieView: UIViewRepresentable {
let bundle: Bundle
let loopMode: LottieLoopMode
let completion: LottieCompletionBlock?
@Environment(\.lottieAnimationProgress) var lottieAnimationProgress

public init(filename: String, bundle: Bundle, loopMode: LottieLoopMode = .playOnce, completion: LottieCompletionBlock? = nil) {
self.filename = filename
Expand All @@ -33,7 +34,7 @@ public struct LottieView: UIViewRepresentable {
animationView.contentMode = .scaleAspectFit
animationView.backgroundBehavior = .pauseAndRestore
if context.environment.disableAnimations {
animationView.currentProgress = 0.5
animationView.currentProgress = lottieAnimationProgress
} else {
animationView.play(completion: completion)
}
Expand Down

0 comments on commit cfb104c

Please sign in to comment.