-1

I want to implement Spring animation using MotionLayout. Also, I want to give stiffness and damping as custom values.

By the way, I saw examples where you need to use the OnSwipe tag to use Spring animation in MotionLayout.

What I want is for animation to work without user's touch.

Is there any way?

tuuks
  • 19
  • 3
  • Or am I misunderstanding something? It's hard to understand because I don't have enough knowledge about animation. – tuuks Feb 14 '23 at 01:23

1 Answers1

1

It is a little unclear what you mean by spring animation. If you want the progress to move in the form of a Spring. So typically you do:

progress.animateTo(
            1f,
            animationSpec = tween(800)
        )
         MotionLayout(
            ...
            progress = progress.value
        ) 

This can be changed to

    val progress by animateFloatAsState(
        targetValue = 1f,
        animationSpec = spring(
            dampingRatio = Spring.DampingRatioHighBouncy,
            stiffness = Spring.StiffnessMedium
        )
    )
    MotionLayout(
            ...
            progress = progress.value
    ) 

You can achieve spring like effects inside of MotionLayout by creating custom interpolation curves.

hoford
  • 4,918
  • 2
  • 19
  • 19