【发布时间】:2023-01-13 04:19:46
【问题描述】:
我想在 Compose 中制作一个这样的按钮: https://pub.dev/packages/flutter_bounceable
但是可点击的方法在我的代码中不起作用。
我试过这段代码,但它有一个错误。 按下按钮,但没有任何动作。 动画效果很好,但不适用于可点击的。
fun Modifier.bounceClick(onClick: () -> Unit,animationDuration: Int = 100,
scaleDown: Float = 0.9f) = composed {
val interactionSource = MutableInteractionSource()
val coroutineScope = rememberCoroutineScope()
val scale = remember {
Animatable(1f)
}
this
.scale(scale = scale.value)
.background(
color = Color(0xFF35898F),
shape = RoundedCornerShape(size = 12f)
)
.clickable(interactionSource = interactionSource, indication = null, onClick = onClick)
.pointerInput(Unit) {
while(true)
awaitPointerEventScope {
awaitFirstDown()
coroutineScope.launch {
scale.animateTo(
scaleDown,
animationSpec = tween(animationDuration),
)
}
waitForUpOrCancellation()
coroutineScope.launch {
scale.animateTo(
scaleDown,
animationSpec = tween(20),
)
scale.animateTo(
1f,
animationSpec = tween(animationDuration),
)
}
}
}
}
【问题讨论】:
标签: android button android-jetpack-compose clickable bounce