Created
October 5, 2022 11:39
-
-
Save cp-radhika-s/6516aaaa7f5b0f955e35cf7040da0dcb 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.pressClickEffect() = composed { | |
var buttonState by remember { mutableStateOf(ButtonState.Idle) } | |
val ty by animateFloatAsState(if (buttonState == ButtonState.Pressed) 0f else -20f) | |
this | |
.graphicsLayer { | |
translationY = ty | |
} | |
.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