Hello! I am a hobbyist trying to learn Android pro...
# compose
m
Hello! I am a hobbyist trying to learn Android programming with Kotlin. I am trying to learn Jetpack Compose by making toy projects. I am currently working on an app that displays XKCD comics complete with double-tap to zoom, pinch, pan and fling gestures. To achieve this, I am currently using two pointerInput with different keys, one to detect double taps using detectTapGestures, and another to detect pans/drags using detectDragGestures. Finally, I am using transformable to detect multi-finger gestures like pinch-zoom. This setup works, but I am not sure that if this is the best way to go about it. I have a number of questions on this: Is it okay to use multiple pointerInput on the same widget? Does it impact performance in any way? What exactly is the role of key1 argument of pointerInput? Should they be different for different pointerInput? It seems that I can't use more than one gesture detectors within the same pointerInput scope, as the first one seems to "consume" the event. Is there any way to prevent this, or is this by design? I can't find many resources on Google where multiple gestures are implemented on the same object.
a
It's ok to use multiple
pointerInput
but you can use
launch
to detect multiple gestures in a single
pointerInput
. The key is used to restart the lambda just like
LaunchedEffect
so it only affects that single
pointerInput
call.
See this which is the same as what you are implementing.
m
@Albert Chang Thanks. I look into it
Your code is exactly what I was looking for 🙂