DotLottieConfiguration.swift 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
//
// DotLottieConfiguration.swift
// Lottie
//
// Created by Evandro Hoffmann on 19/10/22.
//

// MARK: - DotLottieConfiguration

/// The `DotLottieConfiguration` model holds the presets extracted from DotLottieAnimation
///  - The presets are used as input to setup `LottieAnimationView` before playing the animation.
public struct DotLottieConfiguration {

  // MARK: Public

  /// id of the animation
  public var id: String

  /// Loop behavior of animation
  public var loopMode: LottieLoopMode

  /// Playback speed of animation
  public var speed: Double

  /// Animation Image Provider
  public var imageProvider: AnimationImageProvider? {
    dotLottieImageProvider
  }

  // MARK: Internal

  /// The underlying `DotLottieImageProvider` used by this dotLottie animation
  var dotLottieImageProvider: DotLottieImageProvider?
}

// MARK: - DotLottieConfigurationComponents

/// Components of the `DotLottieConfiguration` to apply to the `LottieAnimationView`.
///  - When using `LottieView`, if the component is selected to be applied it will
///    override any value provided via other `LottieView` APIs.
public struct DotLottieConfigurationComponents: OptionSet {

  // MARK: Lifecycle

  public init(rawValue: Int) {
    self.rawValue = rawValue
  }

  // MARK: Public

  /// `DotLottieConfiguration.imageProvider` will be applied to the `LottieAnimationView`
  ///  - When using `LottieView`, the image provider from the dotLottie animation will override
  ///    the image provider applied manually using `LottieView.imageProvider(...)`.
  public static let imageProvider = DotLottieConfigurationComponents(rawValue: 1 << 0)

  /// `DotLottieConfigurationMode.loopMode` will be applied to the `LottieAnimationView`.
  ///  - When using `LottieView`, the loop mode from the dotLottie animation will override
  ///    the loopMode applied by any playback method.
  public static let loopMode = DotLottieConfigurationComponents(rawValue: 1 << 1)

  /// `DotLottieConfigurationMode.speed` will be applied to the `LottieAnimationView`.
  ///  - When using `LottieView`, the speed from the dotLottie animation will override
  ///    the speed applied manually using `LottieView.animationSpeed(...)`.
  public static let animationSpeed = DotLottieConfigurationComponents(rawValue: 1 << 2)

  public static let all: DotLottieConfigurationComponents = [.imageProvider, .loopMode, .animationSpeed]

  public static let none: DotLottieConfigurationComponents = []

  public let rawValue: Int

}