Thinking about touching and holding the finger on ...
# compose-android
t
Thinking about touching and holding the finger on the screen. How can I detect the touch is over a specific composable?
j
It's not clear from your description what you're trying to accomplish. Are you trying to detect long press, or something more advanced? If you're trying to detect long-press, the following should work for you:
Copy code
Modifier.pointerInput(Unit) {
    detectTapGestures(
        onPress = { /* Called when the gesture starts */ },
        onDoubleTap = { /* Called on Double Tap */ },
        onLongPress = { /* Called on Long Press */ },
        onTap = { /* Called on Tap */ }
    )
}
For most advanced usecases, you can typically use a pointerInteropFilter to get input that is a little more raw and calculate your own gestures: https://stackoverflow.com/questions/64571945/how-can-i-get-ontouchevent-in-jetpack-compose You can also take a look at the implementation of
detectTapGestures
to get a better sense of how gesture detection is implemented.
t
It's not long press, I would need the user to tap a button and then some extra buttons would show, then the user can drag the finger to these buttons and when released it would trigger a callback
So it would be nice to have a way to detect the touch is over one of these input
j
pointerInteropFilter should do what you need.
t
Thanks for the north, I'll take a look on it 😄