https://kotlinlang.org logo
Title
j

Javier

01/08/2022, 2:09 PM
Is there an
OnPointerEvent
common API for Desktop and Android?
PointerEventType
is common but the modifier is missing
Found:
...
.pointerInput(
    key1 = Unit,
    block = {
        detectTapGestures(
            onTap = { offset ->
               ...
            }
        )
    }
),
Having a common
detectTapGestures
modifier should be great
a

Adam Powell

01/08/2022, 5:11 PM
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:
.pointerInput(Unit) {
  detectTapGestures(...
j

Javier

01/08/2022, 7:24 PM
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

Adam Powell

01/08/2022, 11:07 PM
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

Javier

01/09/2022, 12:27 AM
awaitPointerInputScope.currentEvent.changes
should be changing the list after every click? It is always empty and the type is
Unknown
.
a

Adam Powell

01/09/2022, 2:51 AM
you'll want to use the
awaitPointerEvent
function to await the next event. Loop as desired.
j

Javier

01/09/2022, 1:09 PM
Is it safe to do
while(true)
?
a

Adam Powell

01/09/2022, 4:08 PM
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
:thank-you: 1
(e.g. awaiting the next event)
j

Javier

01/09/2022, 7:23 PM
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.
Initial: Down the tree from ancestor to descendant.
Main: Up the tree from descendant to ancestor.
Final: Down the tree from ancestor to descendant.