Last active
April 1, 2023 17:45
-
-
Save frogggias/53f1497d2d8219716e03f0ed5689a79c to your computer and use it in GitHub Desktop.
Hacky solution to handle at least some onLongClick events on M3 Button
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
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