Hey, I'm getting started with animations on Compos...
# compose
j
Hey, I'm getting started with animations on Compose by playing with the bottom bar implementation on the Jetsnack sample. Why
indicatorIndex
here doesn't use
animateFloatAsState()
? Is there a difference?
Copy code
+  val indicatorIndex by animateFloatAsState(selectedIndex.toFloat(), animSpec)

-  val indicatorIndex = remember { Animatable(0f) }
-  val targetIndicatorIndex = selectedIndex.toFloat()
-  LaunchedEffect(targetIndicatorIndex) {
-      indicatorIndex.animateTo(targetIndicatorIndex, animSpec)
-  }
d
animateFloatAsState
uses the first
targetValue
that was passed to it as its initial value. But sometimes you may want to have a different initial value (usually as an enter transition) and animate from there to the first target value, in which case you need
Animatable
🙂