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

Code before:
    }

    /// Tell existing context to ignore its closure
    animationContext.closure.ignoreDelegate = true

    /// Make a new context, stealing the completion block from the previous.
    let newContext = AnimationContext(
      playFrom: animationContext.playFrom,
      playTo: animationContext.playTo,
      closure: animationContext.closure.completionBlock)

    /// Remove current animation, and freeze the current frame.
    let pauseFrame = realtimeAnimationFrame
    rootAnimationLayer?.removeAnimation(forKey: activeAnimationName)
    rootAnimationLayer?.currentFrame = pauseFrame

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

  func loadAnimation(_ animationSource: LottieAnimationSource?) {
    switch animationSource {
    case .lottieAnimation(let animation):
      self.animation = animation
    case .dotLottieFile(let dotLottieFile):
      loadAnimation(from: dotLottieFile)
    case nil:
      animation = nil
    }
  }

  // MARK: Fileprivate

  fileprivate var _activeAnimationName: String = LottieAnimationLayer.animationName
  fileprivate var animationID = 0

  fileprivate var activeAnimationName: String {
    switch rootAnimationLayer?.primaryAnimationKey {
    case .specific(let animationKey):
      return animationKey
    case .managed, nil:
      return _activeAnimationName
    }
  }

Review comment (suggestion):
```suggestion

  func updateRasterizationState() {
    if isAnimationPlaying {
      animationLayer?.shouldRasterize = false
    } else {
      animationLayer?.shouldRasterize = shouldRasterizeWhenIdle
    }
  }
```

Code after:
    }

    /// Tell existing context to ignore its closure
    animationContext.closure.ignoreDelegate = true

    /// Make a new context, stealing the completion block from the previous.
    let newContext = AnimationContext(
      playFrom: animationContext.playFrom,
      playTo: animationContext.playTo,
      closure: animationContext.closure.completionBlock)

    /// Remove current animation, and freeze the current frame.
    let pauseFrame = realtimeAnimationFrame
    rootAnimationLayer?.removeAnimation(forKey: activeAnimationName)
    rootAnimationLayer?.currentFrame = pauseFrame

    addNewAnimationForContext(newContext)
  }

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

  func loadAnimation(_ animationSource: LottieAnimationSource?) {
    switch animationSource {
    case .lottieAnimation(let animation):
      self.animation = animation
    case .dotLottieFile(let dotLottieFile):
      loadAnimation(from: dotLottieFile)
    case nil:
      animation = nil
    }
  }

  // MARK: Fileprivate

  fileprivate var _activeAnimationName: String = LottieAnimationLayer.animationName
  fileprivate var animationID = 0

  fileprivate var activeAnimationName: String {
    switch rootAnimationLayer?.primaryAnimationKey {
    case .specific(let animationKey):
      return animationKey
    case .managed, nil:
      return _activeAnimationName
    }
  }