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?
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
1 year ago
I'm not aware of discussions regarding that but that might just be because I haven't used raw touch events much 🙂
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.