louiscad
01/16/2024, 10:22 PManimateFloatAsState(…)
) but only at a certain rate?
My intent is to not cause re-renders at 120fps during the animation, but only 60, 30, 20, or even 15fps, for elements that move only a little, and don't need a high refresh rate animation to feel smooth.Zach Klippenstein (he/him) [MOD]
01/16/2024, 10:23 PMephemient
01/16/2024, 10:29 PMlouiscad
01/16/2024, 10:30 PM%
,wouldn't that work best than delay?louiscad
01/16/2024, 10:30 PMjw
01/16/2024, 10:31 PMZach Klippenstein (he/him) [MOD]
01/16/2024, 10:31 PMjw
01/16/2024, 10:31 PMZach Klippenstein (he/him) [MOD]
01/16/2024, 10:31 PMlouiscad
01/16/2024, 10:33 PMlouiscad
01/16/2024, 10:33 PMjw
01/16/2024, 10:34 PMjw
01/16/2024, 10:34 PMlouiscad
01/16/2024, 10:36 PMlouiscad
01/16/2024, 10:37 PMlouiscad
01/16/2024, 10:42 PMwithFrameNanos
?jw
01/16/2024, 10:44 PMjw
01/16/2024, 10:45 PMephemient
01/16/2024, 10:47 PMval float by animateFloatAsState(value)
by
class SkippingMonotonicFrameClock(private val divisor: Int, private val delegate: MonotonicFrameClock) : MonotonicFrameClock {
override fun <R> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R) {
repeat(divisor - 1) { delegate.withFrameNanos { } }
return delegate.withFrameNanos(onFrame)
}
}
val animatedFloat = remember { Animatable(value) }
LaunchedEffect(value) {
withContext(SkippingMonotonicFrameClock(divisor = 4, delegate = currentCoroutineContext[MonotonicFrameClock]!!)) {
animatedFloat.animateTo(value)
}
}
val float by animatedFloat
that it would only animate on every 4th framelouiscad
01/16/2024, 10:51 PMlouiscad
01/16/2024, 10:53 PMlouiscad
01/16/2024, 10:54 PMromainguy
01/17/2024, 5:06 AMromainguy
01/17/2024, 5:07 AMromainguy
01/17/2024, 5:07 AMephemient
01/17/2024, 5:16 AMephemient
01/17/2024, 5:16 AMlouiscad
01/17/2024, 9:39 AMlouiscad
01/17/2024, 9:43 AM