Is there an `OnPointerEvent` common API for Deskto...
# compose
j
Is there an
OnPointerEvent
common API for Desktop and Android?
PointerEventType
is common but the modifier is missing
Found:
Copy code
...
.pointerInput(
    key1 = Unit,
    block = {
        detectTapGestures(
            onTap = { offset ->
               ...
            }
        )
    }
),
Having a common
detectTapGestures
modifier should be great
a
What is the use case that isn't met by
.clickable
? We didn't find much there to counterbalance people using a tap-input-only modifier when
clickable
would be more appropriate, and then creating a poor experience with regard to missing visual feedback or keyboard/focus behavior
and imo the android studio autocomplete behavior that adds in explicit
key1 =
and
block =
params in calls like that leads to less readable code than the intended form:
Copy code
.pointerInput(Unit) {
  detectTapGestures(...
j
clickable
allows getting the offset click position?
About the autocomplete, it is not caused by Android Studio, I use named params if there are more than one param, but I would like
block
to be renamed to something more descriptive
🤨 1
I have to try, but I am not sure if
detectTapGestures
works if I am pressing a
Button
inside a
Box
, and the
detectTapGestures
is applied to the
Box
itself. Basically I need to know where the user is clicking to do an animation based on that, independently in which children the user clicks.
I have tried and it looks like I was supposing, the click in the child
Button
is not detected by the parent box
a
If you're looking to passively observe input from a parent as children may or may not handle it, you likely want the other facilities of
awaitPointerInputScope
in
pointerInput
. You'll see all events before children do in the initial pass.
👀 1
j
awaitPointerInputScope.currentEvent.changes
should be changing the list after every click? It is always empty and the type is
Unknown
.
a
you'll want to use the
awaitPointerEvent
function to await the next event. Loop as desired.
j
Is it safe to do
while(true)
?
a
So long as you're making a cancelable suspend call in that loop so that cancellation can break out of it when the modifier leaves the composition, yes
🙏 1
(e.g. awaiting the next event)
j
I have the
awaitPointerEvent
in the parent composable, but I can't still detect if the child
Button
is pressed and where was it pressed, I am forced to set that modifier to the
Button
too? I tried all possible passes, no luck.
Copy code
Initial: Down the tree from ancestor to descendant.
Main: Up the tree from descendant to ancestor.
Final: Down the tree from ancestor to descendant.