I don't even know where to begin, nothing similar was ever implemented in Jetpack Compose. How can I make a composable detect 2-finger swipe (or drag) gesture ? Preferably (but not necessarily) without consuming them
Jetpack Compose: Detecting 2-finger swipe or drag gesture
1.1k Views Asked by Yurowitz At
2
There are 2 best solutions below
1

You can achieve multitouch by using transformable
modifier on your composable. Something like this:
@Composable
fun TransformableSample() {
// set up all transformation states
var scale by remember { mutableStateOf(1f) }
var rotation by remember { mutableStateOf(0f) }
var offset by remember { mutableStateOf(Offset.Zero) }
val state = rememberTransformableState { zoomChange, offsetChange, rotationChange ->
scale *= zoomChange
rotation += rotationChange
offset += offsetChange
}
Box(
Modifier
// apply other transformations like rotation and zoom
// on the pizza slice emoji
.graphicsLayer(
scaleX = scale,
scaleY = scale,
rotationZ = rotation,
translationX = offset.x,
translationY = offset.y
)
// add transformable to listen to multitouch transformation events
// after offset
.transformable(state = state)
.background(Color.Blue)
.fillMaxSize()
)
}
More info on Compose gestures can be found here.
I came up with a solution that works consistently. I had to edit the source code for the detectVerticalDragGestures to count the pointers being used, then return the count as parameter in 'onVerticalDrag' like this:
This should also work for detectDragGestures or detectHorizontalDragGestures if you edit the same way I did. Hope it helped.