Repository: airbnb/lottie-ios
File: Sources/Private/MainThread/LayerContainers/CompLayers/TextCompositionLayer.swift (Swift)

Code before:
    let selectedRangeOpacity = rootNode?.textOutputNode.selectedRangeOpacity
    let textRangeUnit = rootNode?.textAnimatorProperties.textRangeUnit

    // Set all of the text layer options
    textLayer.text = textString
    textLayer.font = ctFont
    textLayer.alignment = text.justification.textAlignment
    textLayer.lineHeight = CGFloat(text.lineHeight)
    textLayer.tracking = tracking

    // Configure the text animators
    textLayer.start = start
    textLayer.end = end
    textLayer.textRangeUnit = textRangeUnit
    textLayer.selectedRangeOpacity = selectedRangeOpacity

    let isFillOverridden =
      (fillColorNode.valueProvider as AnyObject) !== (fillColorNode.originalValueProvider as AnyObject)

    textLayer.fillColor =
      if let fillColor = rootNode?.textOutputNode.fillColor {
        fillColor
      } else if isFillOverridden {
        fillColorNode.value.cgColorValue
      } else {
        text.fillColorData?.cgColorValue
      }

    textLayer.preferredSize = text.textFrameSize?.sizeValue
    textLayer.strokeOnTop = text.strokeOverFill ?? false
    textLayer.strokeWidth = strokeWidth
    textLayer.strokeColor = strokeColor
    textLayer.sizeToFit()

    textLayer.opacity = Float(rootNode?.textOutputNode.opacity ?? 1)
    textLayer.transform = CATransform3DIdentity
    textLayer.position = text.textFramePosition?.pointValue ?? CGPoint.zero
    textLayer.transform = matrix
  }

  override func updateRenderScale() {
    super.updateRenderScale()
    textLayer.contentsScale = renderScale
  }
}


Review comment (refactor):
I don't understand why we would need this check or how exactly it impacts how the final fill color is determined, can you include comments explaining the check here and the branches below, and maybe simplify this to something like

```suggestion
      fillColorNode.valueProvider !== fillColorNode.originalValueProvider
```

Code after:
    let selectedRangeOpacity = rootNode?.textOutputNode.selectedRangeOpacity
    let textRangeUnit = rootNode?.textAnimatorProperties.textRangeUnit

    // Set all of the text layer options
    textLayer.text = textString
    textLayer.font = ctFont
    textLayer.alignment = text.justification.textAlignment
    textLayer.lineHeight = CGFloat(text.lineHeight)
    textLayer.tracking = tracking

    // Configure the text animators
    textLayer.start = start
    textLayer.end = end
    textLayer.textRangeUnit = textRangeUnit
    textLayer.selectedRangeOpacity = selectedRangeOpacity

    // Check for an explicit override. If not overridden, we default to `TextDocument`
    // to support transparency (avoiding the default black color of the value provider).
    // `fillColorNode` is non-optional and defaults to black if the color was not overridden.
    // If the color has been overridden, we use the new color: `fillColorNode.value.cgColorValue`.
    // Otherwise, we use the default color from the text: `text.fillColorData?.cgColorValue`.
    //
    // We cannot remove the cast since `AnyValueProvider` is not a class-bound protocol,
    // so we must cast to `AnyObject` to perform an identity comparison.
    let isFillOverridden =
      (fillColorNode.valueProvider as AnyObject) !== (fillColorNode.originalValueProvider as AnyObject)

    textLayer.fillColor =
      if let fillColor = rootNode?.textOutputNode.fillColor {
        fillColor
      } else if isFillOverridden {
        fillColorNode.value.cgColorValue
      } else {
        text.fillColorData?.cgColorValue
      }

    textLayer.preferredSize = text.textFrameSize?.sizeValue
    textLayer.strokeOnTop = text.strokeOverFill ?? false
    textLayer.strokeWidth = strokeWidth
    textLayer.strokeColor = strokeColor
    textLayer.sizeToFit()

    textLayer.opacity = Float(rootNode?.textOutputNode.opacity ?? 1)
    textLayer.transform = CATransform3DIdentity
    textLayer.position = text.textFramePosition?.pointValue ?? CGPoint.zero
    textLayer.transform = matrix
  }

  override func updateRenderScale() {
    super.updateRenderScale()
    textLayer.contentsScale = renderScale