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

Code before:
    }
  }

  // MARK: Internal

  var animationLayer: RootAnimationLayer? = nil

  /// Context describing the animation that is currently playing in this `LottieAnimationView`
  ///  - When non-nil, an animation is currently playing in this layer. Otherwise,
  ///    the layer is paused on a specific frame.
  fileprivate(set) var animationContext: AnimationContext?

  var hasAnimationContext: Bool {
    animationContext != nil
  }

  /// Set animation name from Interface Builder
  var animationName: String? {
    didSet {
      animation = animationName.flatMap {
        LottieAnimation.named($0, animationCache: nil)
      }
    }
  }

  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
  }

  func updateRasterizationState() {
    if isAnimationPlaying {
      animationLayer?.shouldRasterize = false
    } else {
      animationLayer?.shouldRasterize = shouldRasterizeWhenIdle
    }
  }

  /// Updates the animation frame. Does not affect any current animations
  func updateAnimationFrame(_ newFrame: CGFloat) {
    // In performance tests, we have to wrap the animation layer setup
    // in a `CATransaction` in order for the layers to be deallocated at
    // the correct time. The `CATransaction`s in this method interfere
    // with the ones managed by the performance test, and aren't actually
    // necessary in a headless environment, so we disable them.

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

Code after:
    }
  }

  // MARK: Internal

  var animationLayer: RootAnimationLayer? = nil

  /// Context describing the animation that is currently playing in this `LottieAnimationView`
  ///  - When non-nil, an animation is currently playing in this layer. Otherwise,
  ///    the layer is paused on a specific frame.
  fileprivate(set) var animationContext: AnimationContext?

  var hasAnimationContext: Bool {
    animationContext != nil
  }

  /// Set animation name from Interface Builder
  var animationName: String? {
    didSet {
      animation = animationName.flatMap {
        LottieAnimation.named($0, animationCache: nil)
      }
    }
  }

  func updateRasterizationState() {
    if isAnimationPlaying {
      animationLayer?.shouldRasterize = false
    } else {
      animationLayer?.shouldRasterize = shouldRasterizeWhenIdle
    }
  }

  /// Updates the animation frame. Does not affect any current animations
  func updateAnimationFrame(_ newFrame: CGFloat) {
    // In performance tests, we have to wrap the animation layer setup
    // in a `CATransaction` in order for the layers to be deallocated at
    // the correct time. The `CATransaction`s in this method interfere
    // with the ones managed by the performance test, and aren't actually
    // necessary in a headless environment, so we disable them.
    if TestHelpers.performanceTestsAreRunning {
      animationLayer?.currentFrame = newFrame
      animationLayer?.forceDisplayUpdate()
      return
    }

    CATransaction.begin()
    CATransaction.setCompletionBlock {
      self.animationLayer?.forceDisplayUpdate()
    }
    CATransaction.setDisableActions(true)