Irving

    Irving

    1 year ago
    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?
    Afzal Najam

    Afzal Najam

    1 year ago
    Would
    Modifier.draggable
    work for you?
    Irving

    Irving

    1 year ago
    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
    Afzal Najam

    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 🙂
    Adam Powell

    Adam Powell

    1 year ago
    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
    Irving

    Irving

    1 year ago
    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
    b

    Bsn Net

    1 year ago
    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?