Adriano Celentano
01/17/2021, 12:28 PMnickbutcher
01/17/2021, 3:21 PMAdam Powell
01/17/2021, 3:33 PMAdam Powell
01/17/2021, 3:35 PMDoris Liu
01/18/2021, 12:09 AMsuspend fun animate(...)
: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/package-summary#animate. But even this has a bunch of state reads (of the internally created states). I'd be curious what's the motivation for that preference as well. πAdriano Celentano
01/18/2021, 9:45 AMAdriano Celentano
01/18/2021, 10:49 AMAdriano Celentano
01/18/2021, 11:35 AMLaunchedEffect(Unit) {
animate(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
) { _, _ ->
cellGrid.value = calculateNextGrid(cellGrid)
}
}
Doris Liu
01/18/2021, 6:41 PMso this works fine, it just doesnt give me a delay in between each draw (which actually seems fine in my case)Glad you gave it a try! π How would you like the delay to work in your case?
I could make the delay timing myself via coroutines, but i thought i should us an AnimationClock somehow.
withFrameNanos/Millis
is the new AnimationClock. If you need to manipulate the timeline of an animation, you could go one level lower and use the combination of withFrameMillis + TargetBasedAnimation . That would give you more control with more code. π This combo is actually the implementation under the hood for all compose animation APIs (that manage their own lifecycle).Adriano Celentano
01/18/2021, 6:43 PMAdriano Celentano
01/18/2021, 6:45 PMDoris Liu
01/18/2021, 6:55 PMAdriano Celentano
01/18/2021, 7:25 PMLaunchedEffect(Unit) {
while (true) {
cellGrid.value = calculateNextGrid(cellGrid)
delay(300)
}
}
Doris Liu
01/18/2021, 7:35 PMdelay
, which is cancellation cooperative. Wouldn't hurt to make it while(isActive)
, but not super critical.Adriano Celentano
01/18/2021, 7:48 PM