ursus
04/29/2026, 2:39 PMval xOffset by infiniteTransition.animateFloat(
...
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1500, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
)
val brush = Brush.linearGradient( <--------
colors = ...,
start = Offset(xOffset, 0f),
end = Offset(xOffset + widthPx, 0f)
)
I have a infinite transition animation thats needs to animate gradient.
Is there a way to not allocate Brush instance every frame?romainguy
04/29/2026, 2:48 PMromainguy
04/29/2026, 2:48 PMursus
04/29/2026, 2:50 PMromainguy
04/29/2026, 3:06 PMromainguy
04/29/2026, 3:07 PMShaderBrush.transform to apply a scale to your gradient insteadromainguy
04/29/2026, 3:07 PMMatrix to translate it by xOffset and scale by widthPxromainguy
04/29/2026, 3:08 PMromainguy
04/29/2026, 3:08 PMursus
04/29/2026, 3:14 PM