Repository: airbnb/lottie-ios
File: Sources/Public/Animation/LottieAnimationLayer.swift (Swift)

Code before:

  // MARK: Private

  static private let animationName = "Lottie"

  private let logger: LottieLogger

  /// The `LottieBackgroundBehavior` that was specified manually by setting `self.backgroundBehavior`
  private var _backgroundBehavior: LottieBackgroundBehavior?

  /// Whether or not the current animation should be overridden with
  /// the marker matching the current "reduced motion" mode.
  private var shouldOverrideWithReducedMotionAnimation: Bool {
    reducedMotionMarker != nil
  }

  /// The marker that corresponds to the current "reduced motion" mode.
  private var reducedMotionMarker: Marker? {
    switch configuration.reducedMotionOption.currentReducedMotionMode {
    case .standardMotion:
      return nil
    case .reducedMotion:
      return animation?.reducedMotionMarker
    }
  }
  private func loadAnimation(_ dotLottieAnimation: DotLottieFile.Animation) {
    loopMode = dotLottieAnimation.configuration.loopMode
    animationSpeed = CGFloat(dotLottieAnimation.configuration.speed)

    if let imageProvider = dotLottieAnimation.configuration.imageProvider {
      self.imageProvider = imageProvider
    }

    animation = dotLottieAnimation.animation
  }

  /// Plays the marker that corresponds to the current "reduced motion" mode if present.
  private func playReducedMotionAnimation(completion: LottieCompletionBlock?) {
    guard let reducedMotionMarker else { return }

    // `play(marker:)` calls the `play(fromFrame:toFrame:)` method which calls this
    // `playReducedMotionAnimation` method when `shouldOverrideWithReducedMotionAnimation`
    // is `true`. To prevent infinite recursion, disable the reduced motion functionality
    // until the end of this function.
    let currentConfiguration = configuration
    configuration.reducedMotionOption = .standardMotion
    defer { configuration = currentConfiguration }

    play(marker: reducedMotionMarker.name, completion: completion)
  }


Review comment (suggestion):
```suggestion

  private func loadAnimation(_ dotLottieAnimation: DotLottieFile.Animation) {
```

Code after:

  // MARK: Private

  static private let animationName = "Lottie"

  private let logger: LottieLogger

  /// The `LottieBackgroundBehavior` that was specified manually by setting `self.backgroundBehavior`
  private var _backgroundBehavior: LottieBackgroundBehavior?

  /// Whether or not the current animation should be overridden with
  /// the marker matching the current "reduced motion" mode.
  private var shouldOverrideWithReducedMotionAnimation: Bool {
    reducedMotionMarker != nil
  }

  /// The marker that corresponds to the current "reduced motion" mode.
  private var reducedMotionMarker: Marker? {
    switch configuration.reducedMotionOption.currentReducedMotionMode {
    case .standardMotion:
      return nil
    case .reducedMotion:
      return animation?.reducedMotionMarker
    }
  }

  private func loadAnimation(_ dotLottieAnimation: DotLottieFile.Animation) {
    loopMode = dotLottieAnimation.configuration.loopMode
    animationSpeed = CGFloat(dotLottieAnimation.configuration.speed)

    if let imageProvider = dotLottieAnimation.configuration.imageProvider {
      self.imageProvider = imageProvider
    }

    animation = dotLottieAnimation.animation
  }

  /// Plays the marker that corresponds to the current "reduced motion" mode if present.
  private func playReducedMotionAnimation(completion: LottieCompletionBlock?) {
    guard let reducedMotionMarker else { return }

    // `play(marker:)` calls the `play(fromFrame:toFrame:)` method which calls this
    // `playReducedMotionAnimation` method when `shouldOverrideWithReducedMotionAnimation`
    // is `true`. To prevent infinite recursion, disable the reduced motion functionality
    // until the end of this function.
    let currentConfiguration = configuration
    configuration.reducedMotionOption = .standardMotion
    defer { configuration = currentConfiguration }

    play(marker: reducedMotionMarker.name, completion: completion)
  }