NTP-58831 | Add try catch in brush colorstops (#749)

This commit is contained in:
Soumya Ranjan Patra
2025-04-28 17:10:31 +05:30
committed by GitHub
parent 24ab8eb9e7
commit be5d9c57a1

View File

@@ -21,6 +21,7 @@ import androidx.compose.ui.graphics.SweepGradientShader
import com.navi.uitron.model.animations.AnimatedProperties
import com.navi.uitron.model.ui.BrushData
import com.navi.uitron.model.ui.BrushType
import com.navi.uitron.model.ui.ColorStop
import com.navi.uitron.model.ui.OffSetData
class UiTronBrush(
@@ -204,12 +205,22 @@ class UiTronBrush(
}
private val colorData: Array<Pair<Float, Color>> =
brushData?.colorStops?.map { Pair(it.first, it.second.hexToComposeColor) }?.toTypedArray()
?: arrayOf(Pair(0f, Color.Transparent), Pair(1f, Color.Transparent))
convertColorStopToColorData(brushData?.colorStops)
private val processedColorStops = colorData as Array<out Pair<Float, Color>>
private val tileMode = getTileMode(brushData?.tileMode)
private val gradientColors = processedColorStops.map { it.second }
private val gradientColorStops = processedColorStops.map { it.first }
private val gradientWidthMultiplier = brushData?.horizontalEdge ?: 1f
private val gradientHeightMultiplier = brushData?.verticalEdge ?: 1f
private fun convertColorStopToColorData(
colorStops: List<ColorStop>?
): Array<Pair<Float, Color>> {
return try {
colorStops?.map { Pair(it.first, it.second.hexToComposeColor) }?.toTypedArray()
?: arrayOf(Pair(0f, Color.Transparent), Pair(1f, Color.Transparent))
} catch (e: Exception) {
arrayOf(Pair(0f, Color.Transparent), Pair(1f, Color.Transparent))
}
}
}