https://kotlinlang.org logo
#compose
Title
# compose
e

Eric Ampire [MOD]

07/13/2021, 8:17 PM
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

Ravi

07/13/2021, 8:49 PM
Copy code
Modifier.pointerInput(Unit) {
        detectTapGestures(
            onLongPress = {
                onLongClick()
            },
            onPress = {
                onClick()                
            }
        )
    }
can u try this?
e

Eric Ampire [MOD]

07/13/2021, 8:50 PM
I have tried this solution but it doesn't work
t

Tash

07/13/2021, 11:21 PM
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

Eric Ampire [MOD]

07/14/2021, 6:02 AM
It doesn't work too
t

Tash

07/14/2021, 7:39 AM
that snippet works for me. are you able to share more about what you’re trying to do?
p

Pavlo Rybitskyi

08/18/2021, 1:27 PM
Have u figured out how to do it? I'm facing similar issue.
e

Eric Ampire [MOD]

08/18/2021, 7:51 PM
Yes I have used the pointerInput as mentioned by @Tash, and it's work