Marcin Wisniowski
01/22/2024, 7:26 PMrememberInfiniteTransition()
, which looks to be impossible. What would be my alternative?Doris Liu
01/22/2024, 7:29 PMMarcin Wisniowski
01/22/2024, 7:29 PMephemient
01/22/2024, 7:32 PMMarcin Wisniowski
01/22/2024, 7:34 PMephemient
01/22/2024, 7:35 PMMarcin Wisniowski
01/22/2024, 7:36 PMephemient
01/22/2024, 7:38 PMvar isRunning by mutableBooleanStateOf(false)
val animation = Animatable(...)
if (isRunning) {
LaunchedEffect {
while (isActive) {
animation.animateTo(360)
animation.snapTo(0)
}
}
}
Spinner(angle = animation.value)
completely untested but perhaps something like thatMarcin Wisniowski
01/22/2024, 7:43 PMisRunning
becomes false it doesn't stop where it was, but resets. And when it runs again it starts from the beginning.Marcin Wisniowski
01/22/2024, 7:43 PMephemient
01/22/2024, 7:44 PMMarcin Wisniowski
01/22/2024, 7:45 PMsnapTo(saved)
before the animateTo()
ephemient
01/22/2024, 7:47 PMvar angle by mutableFloatStateOf(0f)
LaunchedEffect {
animation.snapTo(angle)
while (isActive) {
animation.animateTo(360) { angle = value }
animation.snapTo(0)
Marcin Wisniowski
01/22/2024, 7:48 PMremember {}
around Animatable(), of course.ephemient
01/22/2024, 7:48 PMMarcin Wisniowski
01/22/2024, 7:48 PMMarcin Wisniowski
01/22/2024, 8:35 PMMarcin Wisniowski
01/22/2024, 8:41 PMval animation = remember { Animatable(0f) }
val target = -360f
if (isHovered) {
LaunchedEffect(Unit) {
while (isActive) {
val remaining = (target - animation.value) / target
animation.animateTo(target, animationSpec = tween((60_000 * remaining).toInt(), easing = LinearEasing))
animation.snapTo(0f)
}
}
}
Ok, this fixes it.ephemient
01/23/2024, 12:04 AManimateDecay
with a custom FloatDecayAnimationSpec
. but that'll turn out to be the same math