My problem:
I need to set image transition animation for some duration. I want to give some spring effects using spring()
spring (stiffness = Spring. StiffnessLow)
But the problem is Jetpack compose animation spec allows one spec at a time. I can able to set either tween() or spring(). But I want both spec in same animation
My code:
@Composable
private fun TransitionAnimation() {
var isAnimated by remember { mutableStateOf(false) }
val transition = updateTransition(targetState = isAnimated, label = "")
val rocketOffset by transition.animateOffset(transitionSpec = {
if (this.targetState) {
tween(1000)
} else {
tween(3000)
//spring(dampingRatio = Spring.DampingRatioLowBouncy) - I want this spec too
}
}, label = "rocket offset") { animated ->
if (animated) Offset(200f, 0f) else Offset(200f, 500f)
}
Image(
painter = painterResource(id = R.drawable.rocket),
contentDescription = "Rocket",
modifier = Modifier
.size(100.dp)
.offset(rocketOffset.x.dp, rocketOffset.y.dp)
)
}