Hi, I have an animation but I don't understand why...
# compose
n
Hi, I have an animation but I don't understand why the boxes are not spaced evenly in it. Please see gif and code in thread. Any ideas?
Copy code
listOf(
            Color(0xffDFFF00),
            Color(0xffFFBF00),
            Color(0xffFF7F50),
            Color(0xffDE3163),
            Color(0xff9FE2BF),
            Color(0xff40E0D0),
            Color(0xff6495ED),
            Color(0xffCCCCFF),
        ).forEachIndexed { index, color ->
            val infiniteTransition = rememberInfiniteTransition()
            val positionState = infiniteTransition.animateFloat(
                initialValue = 0f,
                targetValue = 1f,
                animationSpec = infiniteRepeatable(
                    animation = tween(
                        durationMillis = 2500,
                        delayMillis = delay,
                        easing = LinearEasing
                    )
                )
            )
            delay += 1000

            val modifier = Modifier.offset(
                x = (maxWidth - tileSize),
                y = maxHeight - (maxHeight * positionState.value),
            )

           Box(
                modifier = modifier
                    .size(tileSize)
                    .clip(RoundedCornerShape(5.dp))
                    .background(color = color)
            ) {
                Text(
                    text = text,
                    Modifier.align(Alignment.Center),
                    style = TextStyle(fontWeight = FontWeight.Bold)
                )
            }
s
Their repeats overlap each other I think
👍 1
n
Thanks, any idea how I can avoid that?
s
I would try with single animation and draw everything based on that. e.g with different offsets
n
Ah ok I see, makes sense, thanks!
👍 1