'Is there a way to delay a Spring AnimationSpec in Jetpack Compose Animation?
In Jetpack Compose Animation, for tween AnimationSpec, we can have a delay
val translationY by transition.animateFloat(
transitionSpec = {
tween(
delayMillis = 1000, // Delay here
durationMillis = 2000
)
},
label = ""
) { if (it) 0f else 180f }
However, for Spring AnimationSpec, we only have dampingRatio (0.25f shown below) and Stiffness (100f shown below). There's no way to add a delay.
val translationY by transition.animateFloat(
transitionSpec = {
spring(0.25f, 100f)
},
label = ""
) { if (it) 0f else 180f }
How to add a delay for Animation using Spring AnimationSpec?
Solution 1:[1]
I managed to add the bouncing effect to tween that quite similar to spring. Just use
easing = { OvershootInterpolator().getInterpolation(it) }
OvershootInterpolator comes from android.view.animation package.
You can provide a tension argument into OvershootInterpolator by its constructor to change bounciness.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ilnar Ramazanov |
