Jetpack Compose Gradient #205
Color Stops
| Stop | Preview | Hex | Compose Color |
|---|---|---|---|
| 0% | |||
| 100% |
Jetpack Compose Code
Modifier.drawWithCache {
val angle = Math.toRadians(90.0)
val direction = Offset(sin(angle).toFloat(), -cos(angle).toFloat())
val length = size.width * abs(direction.x) + size.height * abs(direction.y)
val brush = Brush.linearGradient(
colorStops = arrayOf(
0f to Color(0xFFFFD166),
1f to Color(0xFFFF8C42)
),
start = size.center - direction * (length / 2f),
end = size.center + direction * (length / 2f)
)
onDrawBehind { drawRect(brush) }
}