Has anyone found a reliable way to slow down all a...
# compose
z
Has anyone found a reliable way to slow down all animations in compose for debugging purposes? Im aware of the debug option for Android, but would like something that works on desktop & iOS as well.
m
You could probably set the animation duration scale if you just want it to run slower. But i've found for debugging purposes, I prefer to just use a non auto advancing clock:
Copy code
runComposeUiTest {
    mainClock.autoAdvance = false
    ...
}
Then you can just set your content, and advance the clock as you see fit.
z
Im looking into the duration scale; I take it mainClock.autoAdvance is only available in tests?
m
I'm not 100% sure if you can access it outside tests. I can tell you that the "mainClock" symbol is available on both the "ComposeUiTest" (which is the scope for the "runComposeUiTest" block above), and on the "ComposeTestRule" interface. But for actual running of the application, i'd look at animator duration scale. You have to turn on developer settings, but once you do, you can change that at the emulator or physical device level:
but there's limited options at least in my emulator image, with .5 being the slowest
z
Gotcha, from the litte Ive looked (and asked AI 😅); it does not seem to be availabe outside of tests. Im aware of the duration scale option on Android - its pretty much what Id like; I just need it to work on desktop & iOS as well!
k
There is an option in iOS simulator to slow down animations, dunno if that helps 😄
z
Both of these help, now if theres was only something like this for desktop as well?
z
mainClock
is a test-specific thing
z
@Zach Klippenstein (he/him) [MOD] Thank you for the confirmation. If theres anyone that would know how to override something like MotionDurationScale (CoroutineContext.Key) in compose, I think that would be you? 😅 Ive looked at Composition & Recomposer, I think thats where Id specify the context, which then gets used by animations throughout compose, BUT, jeez, it does not seem like its intended to be used by anything outside of the framework. If the different appliers were public, or at least what ComponentActivity.setContent, and respective calls on desktop & iOS does would take some context parameters, we would be rollin. Unless theres another way, I think Im going to call it quits on this idea and keep my custom AnimatedContent/Visibility/!! functions.
Like, on Android, setContent does take CompositionContext as its first parameter, and I think I can pass a recomposer with a different coroutineContext in there. But thats only on Android, on desktop, afaik theres nothing like it.
On desktop, if I were to call awaitApplication with the CoroutineContext specified, I think some of the inner calls override MotionDurationScale. I think Ive spent enough time on this now.. 😅
z
I have no idea if there’s a desktop setting this is wired to, sorry.
z
No worries, Im grateful you took the time to read through my top of mind spam 😃 Ill leave this be, maybe in the future it will be possible without going insane! If anyone wants to open a ticket requesting it, I can definitely star it!