Mikael Alfredsson
01/13/2022, 6:07 PMvar target by remember { mutableStateOf(0.5f) }
val animTarget by animateFloatAsState(targetValue = target, animationSpec = spring(stiffness = 1f)) {
target = Random.nextFloat()
}
LaunchedEffect(key1 = Unit) {
target = Random.nextFloat()
}
Doris Liu
01/13/2022, 6:58 PManimateFloatAsState
is 0.01f. You could tweak the visibilityThreshold
param in animateFloatAsState
to overwrite the default threshold.
Note that the lower the threshold, the longer the animation is going to take to finish. Too large of a threshold would result in a visible jump in the end. The default thresholds are designed to avoid any noticeable visual jump (e.g. half a pixel). If you plot the animation value over time and really zoom in the graph, you will see that last bit of movement to close the gap once the threshold is met.Mikael Alfredsson
01/13/2022, 7:00 PMvisiblilityThreshold
?Doris Liu
01/13/2022, 7:01 PMMikael Alfredsson
01/13/2022, 7:02 PMDoris Liu
01/13/2022, 7:03 PMMikael Alfredsson
01/13/2022, 7:05 PMtarget
value when the animation is as slow as the visibilityThreshold
Doris Liu
01/13/2022, 7:06 PMMikael Alfredsson
01/13/2022, 7:09 PMDoris Liu
01/13/2022, 7:16 PMMikael Alfredsson
01/13/2022, 7:19 PMDoris Liu
01/13/2022, 7:28 PMMikael Alfredsson
01/13/2022, 7:34 PM