Hello guys, I have an Animatable animation running...
# compose
r
Hello guys, I have an Animatable animation running in a coroutine, the problem is that when I put the app in the background, my animation stop, and when I return to the app, my animation has finished instead of continue in the interrupted value. How can I return to the app and continue my animation where I left off?
a
we generally consider this undesirable and prefer the behavior where time isn't stopped by leaving and returning. However, if you'd like to implement such a thing you can implement your own
MonotonicFrameClock
that wraps the current one, install it using
withContext
, and then call the suspending animation functions in that block. e.g.
Copy code
val myPausingClock = MyPausingClock(coroutineContext[MonotonicFrameClock]!!, lifecycleOwner)
withContext(myPausingClock) {
  animateThings()
}
and subtract out the time skipped while the lifecycle isn't
STARTED
or higher from the timestamps passed to
MonotonicFrameClock.withFrameNanos
callers, otherwise just passing it through to the wrapped clock
🔥 3
r
Thanks so much!
👍 1