Se7eN
06/01/2021, 4:04 PMval infiniteTransition = rememberInfiniteTransition()
val progress by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 100f,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
Tash
06/01/2021, 5:13 PMAnimatable
instead, since it exposes a stop()
Se7eN
06/01/2021, 5:26 PMupdateTransition
and came up with this. It's working fine, just wanna make sure if I did it right?Doris Liu
06/01/2021, 6:53 PMupdateTransition
is the best API for this use case. Transition
expects a value associated with each state, and animates to that value when state changes. The initial infinite animation between 0-100 isn't exactly a state. Animatable
would be more suitable for your use case, you can start with an animateTo
using an infinite animation spec, and interrupt it any time with a new target based on the network data.Tash
06/01/2021, 7:01 PMThe initial infinite animation between 0-100 isn’t exactly a stateTo add to that, looks like the snippet is transforming between
MeterHeadState
and a float, clearly indicating that you are trying to make the 0-100 animation into a state just to make it work with updateTransition()
.Se7eN
06/02/2021, 12:48 PMAnimatable
and remove the MeterHeadState
. Thank you both!val progress = remember { Animatable(0f) }
LaunchedEffect(index) {
if (index != null) {
progress.animateTo(
targetValue = index.value.toFloat(),
animationSpec = spring(
Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessVeryLow
)
)
} else {
progress.animateTo(
targetValue = 100f,
animationSpec = infiniteRepeatable(
animation = keyframes {
durationMillis = 800
0f at 0 with FastOutSlowInEasing
100f at 800 with FastOutSlowInEasing
},
repeatMode = RepeatMode.Reverse
)
)
}
}
So I guess I'm doing it right nowDoris Liu
06/02/2021, 6:42 PMSe7eN
06/02/2021, 6:49 PM@Composable
private fun animatedProgress(index: FGIndex?): Float {
val progress = remember { Animatable(0f) }
LaunchedEffect(index) {
if (index != null) {
progress.animateTo(
targetValue = index.value.toFloat(),
animationSpec = ProgressToIndexSpec
)
} else {
progress.animateTo(
targetValue = 100f,
animationSpec = ProgressInfiniteSpec
)
}
}
return progress.value
}
Doris Liu
06/02/2021, 6:54 PMState<Float>
here instead (i.e. progress.asState()
)Se7eN
06/02/2021, 6:57 PM