t3chb0t
t3chb0t

Reputation: 18724

How do you make Text double-clickable?

I've got a Text control in my JetPack Compose desktop application that I'd like to be double-clickable so that users can add its value to a filter. The text is displayed within a LazyColumn as one of several values.

I know you can make it clickable with Modifier.clickable, but how do I make it double-clickable so that it isn't added by accident via a single-click?

Upvotes: 1

Views: 470

Answers (1)

Thracian
Thracian

Reputation: 67248

You can use detectTapGestures(onDoubleTap= {}) which is available inside PointerInputScope as

@Preview
@Composable
private fun Test() {
    
    val context = LocalContext.current
    
    Text(
        modifier = Modifier.pointerInput(Unit){
          detectTapGestures(
              onDoubleTap = {
                  Toast.makeText(context, "Double Tapped", Toast.LENGTH_SHORT).show()
              }
          )  
        },
       text =  "Some Text to Double Tap",
        fontSize = 26.sp
    )
}

Upvotes: 3

Related Questions