Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created October 5, 2022 11:38
Show Gist options
  • Save cp-radhika-s/be3f5f0122d5c177168226e1d8cbc7fd to your computer and use it in GitHub Desktop.
Save cp-radhika-s/be3f5f0122d5c177168226e1d8cbc7fd to your computer and use it in GitHub Desktop.
enum class ButtonState { Pressed, Idle }
fun Modifier.bounceClick() = composed {
var buttonState by remember { mutableStateOf(ButtonState.Idle) }
val scale by animateFloatAsState(if (buttonState == ButtonState.Pressed) 0.70f else 1f)
this
.graphicsLayer {
scaleX = scale
scaleY = scale
}
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = { }
)
.pointerInput(buttonState) {
awaitPointerEventScope {
buttonState = if (buttonState == ButtonState.Pressed) {
waitForUpOrCancellation()
ButtonState.Idle
} else {
awaitFirstDown(false)
ButtonState.Pressed
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment