Skip to content

Commit

Permalink
[BottomSheet] Exposing bottom sheet hide friction with get/set methods.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 449334214
  • Loading branch information
imhappi authored and drchen committed May 18, 2022
1 parent 2ac796f commit be1b38c
Showing 1 changed file with 25 additions and 1 deletion.
Expand Up @@ -292,6 +292,8 @@ void onLayout(@NonNull View bottomSheet) {}

private boolean nestedScrolled;

private float hideFriction = HIDE_FRICTION;

private int childHeight;
int parentWidth;
int parentHeight;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit be1b38c

Please sign in to comment.