https://kotlinlang.org logo
#compose
Title
# compose
i

Irving

10/09/2020, 7:16 AM
Hello, I'm new to Jetpack Compose. I'm confused about how do Touch Events be handled by Compose. For example, if I want to write a custom view and handle touch events by myself. I could override onTouchEvent to do complex gestures before, but how could I do by Compose?
🤣 1
a

Afzal Najam

10/09/2020, 7:19 AM
Would
Modifier.draggable
work for you?
i

Irving

10/09/2020, 7:36 AM
Yes, I've tried Modifier.draggable, it works for me. Then I read the sourse code of it, at the end I found PointerInputFilter class. I guess maybe it handles the Touch Events. So how could I use this Class to handle the Touch Events? And I also want to know How are events passed from the View Tree😀. Is there a post talk about this? I looked long and hard from the channel and the internet but couldn't find it. @Afzal Najam
a

Afzal Najam

10/09/2020, 7:49 AM
I'm not aware of discussions regarding that but that might just be because I haven't used raw touch events much 🙂
😁 1
a

Adam Powell

10/09/2020, 1:18 PM
Events are passed up and down the layout tree in three phases outlined in the PointerEventPass enum class
The PointerInputFilter callback tells you which pass the event is for. Initial and Main roughly correspond to View's onInterceptTouchEvent and onTouchEvent, respectively, and Final lets you see what everything else consumed on previous phases, since compose doesn't fully intercept touch events in the same way when a parent wants to take over, e.g. for scrolling. Child elements can still see the event flow, but those events are marked as consumed.
We're in the process of making it possible to write pointer input processing code using coroutines to express the state machine, since they often get quite gnarly to write in the traditional way: https://android-review.googlesource.com/c/platform/frameworks/support/+/1443300
i

Irving

10/09/2020, 3:25 PM
Thank you for answering my question.I think I've got it.I will continue to focus on new ways to handle Input Events with coroutines😁🙌. @Adam Powell
👍 1
b

Bsn Net

10/10/2020, 5:32 AM
right now using navigation drawer when we touch anywhere in the drawer it will close the navigation drawer. to prevent this should we also use modifier draggable?
18 Views