Jorkoh
02/03/2021, 12:53 PMindicatorIndex
here doesn't use animateFloatAsState()
? Is there a difference?
+ val indicatorIndex by animateFloatAsState(selectedIndex.toFloat(), animSpec)
- val indicatorIndex = remember { Animatable(0f) }
- val targetIndicatorIndex = selectedIndex.toFloat()
- LaunchedEffect(targetIndicatorIndex) {
- indicatorIndex.animateTo(targetIndicatorIndex, animSpec)
- }
Doris Liu
02/04/2021, 2:23 AManimateFloatAsState
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
🙂