From be1b38c30b4383a332e8b0ff297d636789287d99 Mon Sep 17 00:00:00 2001 From: rightnao Date: Tue, 17 May 2022 18:45:41 -0400 Subject: [PATCH] [BottomSheet] Exposing bottom sheet hide friction with get/set methods. PiperOrigin-RevId: 449334214 --- .../bottomsheet/BottomSheetBehavior.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java index e152fd18f6a..f4097dd6c9b 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -292,6 +292,8 @@ void onLayout(@NonNull View bottomSheet) {} private boolean nestedScrolled; + private float hideFriction = HIDE_FRICTION; + private int childHeight; int parentWidth; int parentHeight; @@ -1144,6 +1146,28 @@ public int getSaveFlags() { return this.saveFlags; } + /** + * Sets the friction coefficient to hide the bottom sheet, or set it to the next closest + * expanded state. + * + * @param hideFriction The friction coefficient that determines the swipe velocity needed to + * hide or set the bottom sheet to the closest expanded state. + */ + public void setHideFriction(float hideFriction) { + this.hideFriction = hideFriction; + } + + /** + * Gets the friction coefficient to hide the bottom sheet, or set it to the next closest + * expanded state. + * + * @return The friction coefficient that determines the swipe velocity needed to hide or set the + * bottom sheet to the closest expanded state. + */ + public float getHideFriction() { + return this.hideFriction; + } + /** * Sets a callback to be notified of bottom sheet events. * @@ -1393,7 +1417,7 @@ boolean shouldHide(@NonNull View child, float yvel) { return false; } int peek = calculatePeekHeight(); - final float newTop = child.getTop() + yvel * HIDE_FRICTION; + final float newTop = child.getTop() + yvel * hideFriction; return Math.abs(newTop - collapsedOffset) / (float) peek > HIDE_THRESHOLD; }