Skip to content

Commit

Permalink
[BottomSheet] Updated gesture inset bottom to be saved in separate fi…
Browse files Browse the repository at this point in the history
…eld to fix compounding peek height issue

Follow up for #1472

PiperOrigin-RevId: 323079427
  • Loading branch information
dsn5ft committed Aug 4, 2020
1 parent e72c001 commit 1047370
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public abstract static class BottomSheetCallback {

private MaterialShapeDrawable materialShapeDrawable;

private int gestureInsetBottom;
private boolean gestureInsetBottomIgnored;

/** Default Shape Appearance to be used in bottomsheet */
Expand Down Expand Up @@ -770,15 +771,19 @@ public final void setPeekHeight(int peekHeight, boolean animate) {
// If sheet is already laid out, recalculate the collapsed offset based on new setting.
// Otherwise, let onLayoutChild handle this later.
if (layout && viewRef != null) {
calculateCollapsedOffset();
if (state == STATE_COLLAPSED) {
V view = viewRef.get();
if (view != null) {
if (animate) {
settleToStatePendingLayout(state);
} else {
view.requestLayout();
}
updatePeekHeight(animate);
}
}

private void updatePeekHeight(boolean animate) {
calculateCollapsedOffset();
if (state == STATE_COLLAPSED) {
V view = viewRef.get();
if (view != null) {
if (animate) {
settleToStatePendingLayout(state);
} else {
view.requestLayout();
}
}
}
Expand Down Expand Up @@ -1118,7 +1123,7 @@ private int calculatePeekHeight() {
if (peekHeightAuto) {
return Math.max(peekHeightMin, parentHeight - parentWidth * 9 / 16);
}
return peekHeight;
return peekHeight + (gestureInsetBottomIgnored ? 0 : gestureInsetBottom);
}

private void calculateCollapsedOffset() {
Expand Down Expand Up @@ -1250,7 +1255,8 @@ private void setSystemGestureInsets(@NonNull View child) {
@Override
public WindowInsetsCompat onApplyWindowInsets(
View view, WindowInsetsCompat insets, RelativePadding initialPadding) {
setPeekHeight(peekHeight + insets.getMandatorySystemGestureInsets().bottom);
gestureInsetBottom = insets.getMandatorySystemGestureInsets().bottom;
updatePeekHeight(/* animate= */ false);
return insets;
}
});
Expand Down

0 comments on commit 1047370

Please sign in to comment.