From 0cb37a426d4edba578a57507c96f21cbe4badaf1 Mon Sep 17 00:00:00 2001 From: onebone Date: Wed, 27 Apr 2022 01:39:27 +0900 Subject: [PATCH] flinging delta should not be considered for velocity tracking --- .../java/me/onebone/toolbar/ScrollStrategy.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/me/onebone/toolbar/ScrollStrategy.kt b/lib/src/main/java/me/onebone/toolbar/ScrollStrategy.kt index 71f5287..8b98472 100644 --- a/lib/src/main/java/me/onebone/toolbar/ScrollStrategy.kt +++ b/lib/src/main/java/me/onebone/toolbar/ScrollStrategy.kt @@ -87,7 +87,10 @@ internal class EnterAlwaysNestedScrollConnection( override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { val dy = available.y - tracker.delta(dy) + + if (source == NestedScrollSource.Drag) { + tracker.delta(dy) + } val toolbar = toolbarState.height.toFloat() val offset = offsetY.value.toFloat() @@ -138,7 +141,10 @@ internal class EnterAlwaysCollapsedNestedScrollConnection( override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { val dy = available.y - tracker.delta(dy) + + if (source == NestedScrollSource.Drag) { + tracker.delta(dy) + } val consumed = if(dy > 0) { // expanding: offset -> body -> toolbar val offsetConsumption = dy.coerceAtMost(-offsetY.value.toFloat()) @@ -198,7 +204,10 @@ internal class ExitUntilCollapsedNestedScrollConnection( override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { val dy = available.y - tracker.delta(dy) + + if (source == NestedScrollSource.Drag) { + tracker.delta(dy) + } val consume = if(dy < 0) { // collapsing: toolbar -> body toolbarState.dispatchRawDelta(dy)