Is there anything that can detect drag gesture sta...
# compose
v
Is there anything that can detect drag gesture started and stopped I am currently using it like this:
Copy code
Modifier.pointerInput(Unit) {
    detectTransformGestures { centroid, pan, zoom, rotation ->
        offset += pan
        scale *= zoom
    }
}
I am zooming the image and I need to know when the zoom drag is ended like we removed the fingers? Further info 👇
I want to use zooming + panning/dragging But when I use
detectTransformGestures
, I can't control
onDragEnd: () -> Unit
, there is no such param
But when I use
detectDragGestures
, I have
onDragEnd: () -> Unit
, But I can't control zooming , only I can control panning/dragging
a
You can use both. See my implementation.
🙏 1
m
I stumbled over the same issue some time ago and I think it is an omission in the API which makes things unnecessarily complicated.
v
@Michael Paus yeah I think so 😄, but there are some things to look in the above repo
a
IMO current API with coroutines integrated is much better compared to touch event handling in the view system as it allows you to separate logics of handling different gestures while in the view system you have to mix all the logics. If you want to detect multiple gestures, just use multiple
detect*Gestures
functions. Nothing counterintuitive.
v
I tried using it like
Copy code
Modifier.pointerInput(Unit) {
    detectTransformGestures { centroid, pan, zoom, rotation ->
        offset += pan
        scale *= zoom
    }
    detectDragGestures {
       // used onDragEnd() something here
    }
}
But this thing didn't work and only the lambda fun used first was working only
@Albert Chang I looked into your Repo, this thing looks complex but I have no other option I guess
a
As those are suspend functions, you need to use
coroutineScope
and
launch
as shown here. If you are familiar with coroutines, there’s nothing special here.
m
@Vivek Sharma Somewhere else here in kotlinlang I was told that putting multiple detect*s into a single pointerInput is wrong. One should always do it like this:
Copy code
Modifier
.pointerInput(Unit) {
    detectTransformGestures { centroid, pan, zoom, rotation ->
        offset += pan
        scale *= zoom
    }
}
.pointerInput(Unit) {
    detectDragGestures {
       // used onDragEnd() something here
    }
}
But this won’t change anything here because
detectTransformGestures
and
detectDragGestures
are mutually exclusive.
v
I also tried using this before asking here! And I found that they don't behave as we want and here only one thing was working , other was not
a
That’s why I’m using
Modifier.transformable()
instead of
detectTransformGestures
.
v
But can we control
onDragEnd
something like that in
Modifier.transformable()
?
a
You can't so I said you can use both.
@Michael Paus To be clear, detecting multiple gestures in the same
PointerInputScope
is valid as documented here.
More than one 
awaitPointerEventScope
 can run concurrently in the same 
PointerInputScope
 by using 
kotlinx.coroutines.launch
. `block`s are dispatched to in the order in which they were installed.
Also see design note here.
m