I tried to rotate an Icon() using animateFloatAsState.
log("CurrentWeatherLayout", "refreshState:"+weatherInfo?.refreshState)
val rotation: Float by animateFloatAsState(
targetValue = if (weatherInfo?.refreshState == 0) -360f else 0f,
animationSpec = InfiniteRepeatableSpec(
animation = tween(
easing = LinearOutSlowInEasing,
durationMillis = 2000
), repeatMode = RepeatMode.Restart
), label = ""
)
Icon(
tint = Color.Unspecified,
modifier = Modifier
.size(40.dp)
.graphicsLayer {
rotationZ = rotation
},
painter = painterResource(id = R.drawable.ic_refresh),
contentDescription = "refresh"
)
When ‘refreshState’ is 0,Icon() starts to rotate,but when ‘refreshState’ is 1,Icon() startes to revers.
I printed ‘rotation’ value,When ‘refreshState’ is 1,The value will change from 0 to 360,But when ‘refreshState’ is 1,The value will change from 360 to 0.
Why is that? How do I stop animateFloatAsState from generating new values