6

I have a LazyColumn of Text(). I've set clickable for Text() but it's equivalent to OnClickListner. Now I want to set an equivalent of setOnLongClickListener. How can I do that?

@Composable
fun MyText(name: String, modifier: Modifier = Modifier) {

  var isSelected by remember {
        mutableStateOf(false)
    }
        Text(
            text = "Hello $name!",
            modifier = modifier
                .clickable { isSelected = !isSelected }
                .padding(16.dp)
        )
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
TinaTT2
  • 366
  • 5
  • 17

1 Answers1

16

You can use the combinedClickable modifier to get the different click events:

Text(
    text = text,
    modifier = Modifier
        .combinedClickable(
            onLongClick = { /*....*/ },
            onClick ={ /*....*/ })
        .padding(16.dp)
)

Notice that it is an @ExperimentalFoundationApi feature and is likely to change or be removed in the future.

TinaTT2
  • 366
  • 5
  • 17
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841