hey weird animation question : when using animate...
# compose
n
hey weird animation question : when using animate*AsState how come i have to set the targetvalue after “animate*AsState” has been created and not just when its initially setup in order for it to run. (Code in thread)
Working
Copy code
var targetValue by remember { mutableStateOf(0) }

val value by animateIntAsState(
    targetValue = targetValue,
    animationSpec = infiniteRepeatable(
        animation = tween(durationMillis = (targetValue * 5000), easing = LinearEasing),
        repeatMode = RepeatMode.Restart
    )
)

LaunchedEffect(Unit){
   targetValue = descriptions.size
}
Not Working
Copy code
val value by animateIntAsState(
    targetValue = 10,
    animationSpec = infiniteRepeatable(
        animation = tween(durationMillis = (10 * 5000), easing = LinearEasing),
        repeatMode = RepeatMode.Restart
    )
)
Perhaps its just the way I’m using it?
a
What do you want to achieve? What should the initial value of
value
be? The doc explains it well. Basically use
animate*AsState
when the animation is state-based, which doesn't look like your case.
n
desired behaviour would be the value starts at 0 and moves up to targetValue. I’m not super clear on why it wouldn’t run with the initial target value? The actual use case is show looping text from a list of strings. The value being the index into it.
a
animate*AsState
doesn't allow you to specify initial value because it's purely state-based and the initial value is just the value of the first state. The example shows the usage of it.
For your use case, rememberInfiniteTransition may be a better fit.
3
n
I’ll take a stab with rememberInfiniteTransition. Thanks!