Created
October 5, 2022 11:38
-
-
Save cp-radhika-s/be3f5f0122d5c177168226e1d8cbc7fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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