Skip to content

Commit

Permalink
Merge pull request onebone#47 from onebone/fix/velocity-tracking
Browse files Browse the repository at this point in the history
Fix velocity tracker is considering wrong values
  • Loading branch information
onebone authored Jun 9, 2022
2 parents 66d04bb + 0cb37a4 commit f76bd79
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/src/main/java/me/onebone/toolbar/ScrollStrategy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f76bd79

Please sign in to comment.