Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created October 5, 2022 11:39
Show Gist options
  • Save cp-radhika-s/6516aaaa7f5b0f955e35cf7040da0dcb to your computer and use it in GitHub Desktop.
Save cp-radhika-s/6516aaaa7f5b0f955e35cf7040da0dcb to your computer and use it in GitHub Desktop.
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