Skip to content

Instantly share code, notes, and snippets.

@chiragthummar
Created July 1, 2023 04:57
Show Gist options
  • Save chiragthummar/30337a7db53d3fc626c386e766b3d890 to your computer and use it in GitHub Desktop.
Save chiragthummar/30337a7db53d3fc626c386e766b3d890 to your computer and use it in GitHub Desktop.
@Composable
fun ButtonStateExample() {
val interactionSource = remember { MutableInteractionSource() }
val isButtonPressed by interactionSource.collectIsPressedAsState()
val isButtonDragged by interactionSource.collectIsDraggedAsState()
val isButtonHovered by interactionSource.collectIsHoveredAsState()
val isButtonFocused by interactionSource.collectIsFocusedAsState()
LaunchedEffect(key1 = isButtonDragged) {
when {
isButtonDragged -> {/*Button Started Dragging*/ }
else -> {/*Button Drag Cancel*/ }
}
}
LaunchedEffect(key1 = isButtonPressed) {
when {
isButtonPressed -> {/*Button Press*/ }
else -> {/*Button Press Cancel*/ }
}
}
LaunchedEffect(key1 = isButtonHovered) {
when {
isButtonHovered -> {/*Button Hovered*/ }
else -> {/*Button Hovered Cancel*/ }
}
}
LaunchedEffect(key1 = isButtonFocused) {
when {
isButtonFocused -> {/*Button Focused*/ }
else -> {/*Button Cancel Focus*/ }
}
}
FloatingActionButton(
interactionSource = interactionSource, onClick = {}
) {
//Icon
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment