LottieConfiguration.swift 1.9 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
// Created by Cal Stephens on 12/13/21.
// Copyright © 2021 Airbnb Inc. All rights reserved.

import QuartzCore

/// Global configuration options for Lottie animations
public struct LottieConfiguration: Hashable {

  // MARK: Lifecycle

  public init(
    renderingEngine: RenderingEngineOption = .automatic,
    decodingStrategy: DecodingStrategy = .dictionaryBased,
    colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB(),
    reducedMotionOption: ReducedMotionOption = .systemReducedMotionToggle)
  {
    self.renderingEngine = renderingEngine
    self.decodingStrategy = decodingStrategy
    self.colorSpace = colorSpace
    self.reducedMotionOption = reducedMotionOption
  }

  // MARK: Public

  /// The global configuration of Lottie,
  /// which applies to all `LottieAnimationView`s by default.
  public static var shared = LottieConfiguration()

  /// The rendering engine implementation to use when displaying an animation
  ///  - Defaults to `RenderingEngineOption.automatic`, which uses the
  ///    Core Animation rendering engine for supported animations, and
  ///    falls back to using the Main Thread rendering engine for
  ///    animations that use features not supported by the Core Animation engine.
  public var renderingEngine: RenderingEngineOption

  /// The decoding implementation to use when parsing an animation JSON file
  public var decodingStrategy: DecodingStrategy

  /// Options for controlling animation behavior in response to user / system "reduced motion" configuration.
  ///  - Defaults to `ReducedMotionOption.systemReducedMotionToggle`, which returns `.reducedMotion`
  ///    when the system `UIAccessibility.isReduceMotionEnabled` option is `true`.
  public var reducedMotionOption: ReducedMotionOption

  /// The color space to be used for rendering
  ///  - Defaults to `CGColorSpaceCreateDeviceRGB()`
  public var colorSpace: CGColorSpace
}