Hi, since `Card` and Surface have the `onClick` pa...
# compose
e
Hi, since
Card
and Surface have the
onClick
parameter how can I define an
onLongClick
assuming that the code below does not work
Copy code
Modifier.combinedClickable(
    onLongClick = {
      Timber.e("Long Click")
    }
)
Modifier.genericClickableWithoutGesture
that support
onLongClick
is marked as internal
r
Copy code
Modifier.pointerInput(Unit) {
        detectTapGestures(
            onLongPress = {
                onLongClick()
            },
            onPress = {
                onClick()                
            }
        )
    }
can u try this?
e
I have tried this solution but it doesn't work
t
Are you trying to detect long press on a
Card
?
something like this should work
Copy code
@Composable
fun Test() {
    var pressType by remember { mutableStateOf("none") }
    Card(
        modifier = Modifier
            .fillMaxSize(0.6f)
            .pointerInput(Unit) {
                detectTapGestures(
                    onLongPress = {
                        pressType = "onLongPress"
                    },
                    onPress = {
                        pressType = "onPress"
                    }
                )
            },
        backgroundColor = Color.LightGray
    ) {
        Box(modifier = Modifier.fillMaxSize(0.5f)) {
            Text("Press type = $pressType")
        }
    }
}
e
It doesn't work too
t
that snippet works for me. are you able to share more about what you’re trying to do?
p
Have u figured out how to do it? I'm facing similar issue.
e
Yes I have used the pointerInput as mentioned by @Tash, and it's work