Fixes ScrollScope#dispatchScroll returning available instead of consumed delta
This change makes it consistent with other APIs / internal functions
Test: existing tests
Change-Id: I0357e38b5f49427497494c1440c2a75ee82fe697
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
index aab5ed0..7aac595 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
@@ -350,6 +350,9 @@
fun Offset.reverseIfNeeded(): Offset = if (reverseDirection) this * -1f else this
+ /**
+ * @return the amount of scroll that was consumed
+ */
fun ScrollScope.dispatchScroll(availableDelta: Offset, source: NestedScrollSource): Offset {
val scrollDelta = availableDelta.singleAxisOffset()
val overscrollPreConsumed = overscrollPreConsumeDelta(scrollDelta, source)
@@ -376,7 +379,7 @@
source
)
- return leftForParent - parentConsumed
+ return overscrollPreConsumed + preConsumedByParent + axisConsumed + parentConsumed
}
fun overscrollPreConsumeDelta(
@@ -447,8 +450,7 @@
var result: Velocity = available
scrollableState.scroll {
val outerScopeScroll: (Offset) -> Offset = { delta ->
- val consumed = this.dispatchScroll(delta.reverseIfNeeded(), Fling)
- delta - consumed.reverseIfNeeded()
+ dispatchScroll(delta.reverseIfNeeded(), Fling).reverseIfNeeded()
}
val scope = object : ScrollScope {
override fun scrollBy(pixels: Float): Float {