This is what we would currently use in typical Views: https://developer.android.com/reference/android/view/View.OnTouchListener
Is there an equivalent in Jetpack Compose?
This is what we would currently use in typical Views: https://developer.android.com/reference/android/view/View.OnTouchListener
Is there an equivalent in Jetpack Compose?
In compose beta-05 version, you can use:
Text("Your Composable", modifier = Modifier.pointerInput(Unit) {
detectTransformGestures { centroid, pan, zoom, rotation ->
}
// or
detectDragGestures { change, dragAmount -> }
// or
detectTapGestures(
onPress = { offset -> },
onDoubleTap = { offset -> },
onLongPress = { offset -> },
onTap = { offset -> }
)
// or other similar...
})
With 1.0.0 you can use the PointerInput mod
For example you can use detectTapGestures:
Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = {/* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
or the detectDragGestures:
Box(
Modifier
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
//...
}
}
)
You can also use some modifiers like: .scrollable, .clickable, .draggable, .swipeable.