Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MotionDurationScale in the coroutine context #2618

Open
yogurtearl opened this issue Mar 3, 2025 · 2 comments
Open

Support MotionDurationScale in the coroutine context #2618

yogurtearl opened this issue Mar 3, 2025 · 2 comments

Comments

@yogurtearl
Copy link

yogurtearl commented Mar 3, 2025

Compose has a MotionDurationScale coroutine key.

see https://developer.android.com/reference/kotlin/androidx/compose/ui/MotionDurationScale

Lottie compose animations should read and use that animation scale.

Should be able to override the MotionDurationScale by using

withContext(CustomMotionDurationScale) { 
      // lottie compose stuff
 }

(this is does not seem to be supported as of Lottie Compose 6.6.2 )

@yogurtearl
Copy link
Author

In the meantime, as a workaround, can do something like this:

   val animatable = rememberLottieAnimatable()     
   LaunchedEffect(Unit) {
           val motionDurationScale = coroutineContext[MotionDurationScale]?.scaleFactor ?: 1f
            animatable.animate(
                composition,
                speed = animatable.speed / motionDurationScale,
        ....

Also, MotionDurationScale should maybe be used instead of this bit?

// Dividing by 0 correctly yields Float.POSITIVE_INFINITY here.
val actualSpeed = if (ignoreSystemAnimatorScale) speed else (speed / Utils.getAnimationScale(LocalContext.current))

@yogurtearl
Copy link
Author

yogurtearl commented Mar 4, 2025

Also, animatable.animate(...) seems to currently always ignore the animation scale regardless of the value of ignoreSystemAnimationsDisabled passed in, which seems like a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant