diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java index a66afab8d73..8f5e4b34428 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -326,6 +326,8 @@ void onLayout(@NonNull View bottomSheet) {} private int lastNestedScrollDy; + private float lastNestedFlingVelocityY; + private boolean nestedScrolled; private float hideFriction = HIDE_FRICTION; @@ -775,6 +777,7 @@ public boolean onStartNestedScroll( int type) { lastNestedScrollDy = 0; nestedScrolled = false; + lastNestedFlingVelocityY = 0; return (axes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0; } @@ -884,7 +887,10 @@ public void onStopNestedScroll( targetState = STATE_EXPANDED; } } - } else if (hideable && shouldHide(child, getYVelocity())) { + } else if (hideable + && shouldHide( + child, + lastNestedFlingVelocityY != 0 ? lastNestedFlingVelocityY : getYVelocity())) { targetState = STATE_HIDDEN; } else if (lastNestedScrollDy == 0) { int currentTop = child.getTop(); @@ -953,9 +959,15 @@ public boolean onNestedPreFling( float velocityY) { if (isNestedScrollingCheckEnabled() && hasScrollingChild()) { - return isViewScrollingChild(target) - && ((state != STATE_EXPANDED && !draggableOnNestedScrollLastDragIgnored) - || super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY)); + boolean consumed = + isViewScrollingChild(target) + && ((state != STATE_EXPANDED && !draggableOnNestedScrollLastDragIgnored) + || super.onNestedPreFling( + coordinatorLayout, child, target, velocityX, velocityY)); + if (consumed) { + lastNestedFlingVelocityY = velocityY; + } + return consumed; } else { return false; }