https://kotlinlang.org logo
k

Kazemihabib1996

06/12/2020, 8:22 AM
What happens when we
Copy code
return the amount of the [dragDistance] that has been consumed.
? I'm trying to understand the below sentence
Copy code
consume all delta no matter the bounds to avoid nested dragging (as example)
https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/ui/ui-foundation/samples/src/main/java/androidx/ui/foundation/samples/DraggableSamples.kt#100
m

matvei

06/12/2020, 10:14 AM
Hello! Good question 🙂
So in dragging in compose we have a build-in nested dradding via delta consumption. It means that every draggable/ scrollable thing should consume as much as it needs and report the amount consumed, so underlying infrastructure redirect this delta on the parent above the hierarchy. This enables nested dragging "by default", because if your draggable thing hits the bound and stops consuming deltas (returns 0), some parent, which is also scrollable, will start scrolling. In the example we're developing seekbar (slider-like) component and we don't want to participate in the nested dragging (we don't want to open navigation drawer when you hit the bound on the horizontal slider)
👍 1
Agree that documentaiton and example are quite confusing, will try to come up with something better. Hit me up with any questions that you have please 🙂
k

Kazemihabib1996

06/12/2020, 12:31 PM
@matvei Thank you, for your nice explanation based on your scroller example, I write the below code, and understood it completely
Copy code
HorizontalScroller {
   Row {
     repeat(10) { Text("Text $it") }

      DraggableSample()
      repeat(10) { Text("Text $it") }
    }
}
m

matvei

06/12/2020, 12:34 PM
Yay! Happy to help and explain!
👍 1