Alexander Maryanovsky
05/18/2022, 8:15 AMAlexander Maryanovsky
05/18/2022, 8:17 AMvar bounce by remember{ mutableStateOf(false) }
Button(onClick = { bounce = true })
val scale by animateFloatAsState(
targetValue = if (bounce) 1.2f else 1.0f,
finishedListener = {
bounce = false
}
}
Text("Text", modifier = Modifier.scale(scale))
Alexander Maryanovsky
05/18/2022, 8:19 AMfinishedListener
is called and sets bounce=false
and immediately after that onClick
is called and sets bounce=true
. Since scale is already at 1.2, it gets stuck there.Yann Badoual
05/18/2022, 8:40 AManimationSpec
parameter
https://developer.android.com/jetpack/compose/animation#customize-animationsAlexander Maryanovsky
05/18/2022, 8:43 AMFilip Wiesner
05/18/2022, 8:43 AMAnimatable
. It has suspend animateTo()
function so in your case you could write something like this:
scope.launch {
bounce.animateTo(1.2f)
bounce.animateTo(1f)
}
Alexander Maryanovsky
05/18/2022, 8:44 AMAnimatable
Filip Wiesner
05/19/2022, 2:57 PMAnimatable
work out for you?Alexander Maryanovsky
05/26/2022, 8:03 AMval scale = remember { Animatable(1.0f) }
val coroutineScope = rememberCoroutineScope()
if (highlight){
coroutineScope.launch {
val animationSpec = spring<Float>(
dampingRatio = Spring.DampingRatioLowBouncy,
stiffness = (0.9f * Spring.StiffnessMedium + 0.1f * Spring.StiffnessHigh)
)
scale.animateTo(1.1f, animationSpec = animationSpec)
scale.animateTo(1.0f, animationSpec = animationSpec)
}
}
Text(
text = text,
color = MaterialTheme.colors.error,
style = MaterialTheme.typography.caption,
modifier = Modifier.scale(scale.value)
)