TP-61758 App is crashing on sending brushData as emptyArray (#394)
This commit is contained in:
@@ -281,12 +281,14 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
|
||||
fontWeight = uiTronDependencyProvider.getFontWeight(textProperty.fontWeight),
|
||||
fontSize = textProperty.fontSize?.sp ?: 14.sp,
|
||||
brush =
|
||||
getBrush(
|
||||
animatedProperties = animatedProperties,
|
||||
brushData = brushData,
|
||||
height = textHeight?.toFloat(),
|
||||
width = textWidth?.toFloat()
|
||||
),
|
||||
brushData?.let {
|
||||
getBrush(
|
||||
animatedProperties = animatedProperties,
|
||||
brushData = it,
|
||||
height = textHeight?.toFloat(),
|
||||
width = textWidth?.toFloat()
|
||||
)
|
||||
},
|
||||
textDecoration = getTextDecoration(textProperty.textDecoration),
|
||||
letterSpacing = textProperty.letterSpacing?.sp ?: 0.sp,
|
||||
)
|
||||
|
||||
@@ -499,35 +499,35 @@ fun getTileMode(tileMode: String?): TileMode {
|
||||
}
|
||||
|
||||
fun getBrush(
|
||||
brushData: BrushData?,
|
||||
brushData: BrushData,
|
||||
height: Float? = Float.POSITIVE_INFINITY,
|
||||
width: Float? = Float.POSITIVE_INFINITY,
|
||||
animatedProperties: AnimatedProperties? = null
|
||||
): Brush {
|
||||
brushData ?: return Brush.horizontalGradient(colorStops = emptyArray())
|
||||
val colorStops: Array<Pair<Float, Color>>? =
|
||||
brushData.colorStops?.map { Pair(it.first, it.second.hexToComposeColor) }?.toTypedArray()
|
||||
|
||||
val colorStops =
|
||||
brushData.colorStops?.map { it.first to it.second.hexToComposeColor }?.toTypedArray()
|
||||
?: emptyArray()
|
||||
val finalColorStops = colorStops as Array<out Pair<Float, Color>>
|
||||
|
||||
return when (brushData.brushType) {
|
||||
BrushType.HORIZONTAL.name ->
|
||||
horizontalBrush(colorStops, width, animatedProperties, brushData)
|
||||
horizontalBrush(finalColorStops, width, animatedProperties, brushData)
|
||||
BrushType.LINEAR.name ->
|
||||
linearBrush(colorStops, width, height, animatedProperties, brushData)
|
||||
BrushType.RADIAL.name -> radialBrush(colorStops, brushData)
|
||||
BrushType.SWEEP.name -> sweepBrush(colorStops, brushData)
|
||||
BrushType.VERTICAL.name -> verticalBrush(colorStops, height, animatedProperties, brushData)
|
||||
linearBrush(finalColorStops, width, height, animatedProperties, brushData)
|
||||
BrushType.RADIAL.name -> radialBrush(finalColorStops, brushData)
|
||||
BrushType.SWEEP.name -> sweepBrush(finalColorStops, brushData)
|
||||
BrushType.VERTICAL.name ->
|
||||
verticalBrush(finalColorStops, height, animatedProperties, brushData)
|
||||
else ->
|
||||
Brush.verticalGradient(
|
||||
colorStops = emptyArray(),
|
||||
colorStops = finalColorStops,
|
||||
tileMode = getTileMode(brushData.tileMode)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun horizontalBrush(
|
||||
colorStops: Array<Pair<Float, Color>>,
|
||||
colorStops: Array<out Pair<Float, Color>>,
|
||||
width: Float?,
|
||||
animatedProperties: AnimatedProperties?,
|
||||
brushData: BrushData?
|
||||
@@ -543,7 +543,7 @@ private fun horizontalBrush(
|
||||
}
|
||||
|
||||
private fun verticalBrush(
|
||||
colorStops: Array<Pair<Float, Color>>,
|
||||
colorStops: Array<out Pair<Float, Color>>,
|
||||
height: Float?,
|
||||
animatedProperties: AnimatedProperties?,
|
||||
brushData: BrushData?
|
||||
@@ -559,7 +559,7 @@ private fun verticalBrush(
|
||||
}
|
||||
|
||||
private fun linearBrush(
|
||||
colorStops: Array<Pair<Float, Color>>,
|
||||
colorStops: Array<out Pair<Float, Color>>,
|
||||
width: Float?,
|
||||
height: Float?,
|
||||
animatedProperties: AnimatedProperties?,
|
||||
@@ -595,7 +595,7 @@ private fun linearBrush(
|
||||
)
|
||||
}
|
||||
|
||||
private fun radialBrush(colorStops: Array<Pair<Float, Color>>, brushData: BrushData?): Brush {
|
||||
private fun radialBrush(colorStops: Array<out Pair<Float, Color>>, brushData: BrushData?): Brush {
|
||||
return Brush.radialGradient(
|
||||
colorStops = colorStops,
|
||||
tileMode = getTileMode(brushData?.tileMode),
|
||||
@@ -605,7 +605,7 @@ private fun radialBrush(colorStops: Array<Pair<Float, Color>>, brushData: BrushD
|
||||
)
|
||||
}
|
||||
|
||||
private fun sweepBrush(colorStops: Array<Pair<Float, Color>>, brushData: BrushData?): Brush {
|
||||
private fun sweepBrush(colorStops: Array<out Pair<Float, Color>>, brushData: BrushData?): Brush {
|
||||
return Brush.sweepGradient(
|
||||
colorStops = colorStops,
|
||||
center =
|
||||
|
||||
Reference in New Issue
Block a user