Skip to content

Instantly share code, notes, and snippets.

@frogggias
Last active April 1, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogggias/53f1497d2d8219716e03f0ed5689a79c to your computer and use it in GitHub Desktop.
Save frogggias/53f1497d2d8219716e03f0ed5689a79c to your computer and use it in GitHub Desktop.
Hacky solution to handle at least some onLongClick events on M3 Button
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
@Composable
fun LongClickHackBox(
onClick: (() -> Unit)?,
onLongClick: (() -> Unit)?,
component: @Composable () -> Unit,
) {
if (onLongClick == null) {
component()
} else {
Box {
component()
Box(
modifier = Modifier
.matchParentSize()
.pointerInput(Unit) {
detectTapGestures(
onTap = { onClick?.invoke() },
onLongPress = { onLongClick.invoke() }
)
},
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment