How can I add a `onLongClick` event handler to a b...
# compose
n
How can I add a
onLongClick
event handler to a button? There is no parameter in the constructor. I tried with
Modifier.combinedClickable
with a
onLongClick
event listener. But it isn't working.
Copy code
Column(modifier = Modifier.padding(30.dp)) {
        Button(
            onClick = {
                Toast.makeText(
                    applicationContext,
                    "hi",
                    Toast.LENGTH_SHORT
                ).show()
            },
            modifier = Modifier.combinedClickable(
                onLongClick = {
                    Toast.makeText(
                        applicationContext,
                        "hello",
                        Toast.LENGTH_SHORT
                    ).show()
                },
                onClick = {}
            )
        ) {
            Text(text = "Click Me")
        }
    }
}
🧵 1
c
I do not think it is possible. The internal
Surface
will add its
Modifier.clickable
always at the end of the chain.
Copy code
modifier
                .shadow(elevation, shape, clip = false)
                .then(if (border != null) Modifier.border(border, shape) else Modifier)
                .background(
                    color = backgroundColor,
                    shape = shape
                )
                .clip(shape)
                .then(clickAndSemanticsModifier) // HERE!
n
@Csaba Kozák Yep... I too think so... May be I will use a
Box
and make it look like a button...
r
See recent discussion here  and an older post here .