From 0df77248d508ee59d0f2d9966e88f08f73a89610 Mon Sep 17 00:00:00 2001 From: dniz Date: Mon, 10 Aug 2020 15:44:55 -0400 Subject: [PATCH] [BottomSheet] Changed bottom gesture inset handling to ensure a minimum peek height with a buffer built in, instead of always adding the inset to the peek height (when gesture nav is enabled) PiperOrigin-RevId: 325866040 --- .../material/bottomsheet/BottomSheetBehavior.java | 12 +++++++++++- 1 file changed, 11 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 b450baa019a..a3bb438228c 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -205,6 +205,9 @@ public abstract static class BottomSheetCallback { /** Minimum peek height permitted. */ private int peekHeightMin; + /** Peek height gesture inset buffer to ensure enough swipeable space. */ + private int peekHeightGestureInsetBuffer; + /** True if Behavior has a non-null value for the @shapeAppearance attribute */ private boolean shapeThemingEnabled; @@ -275,6 +278,10 @@ public BottomSheetBehavior() {} public BottomSheetBehavior(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); + + peekHeightGestureInsetBuffer = + context.getResources().getDimensionPixelSize(R.dimen.mtrl_min_touch_target_size); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout); this.shapeThemingEnabled = a.hasValue(R.styleable.BottomSheetBehavior_Layout_shapeAppearance); boolean hasBackgroundTint = a.hasValue(R.styleable.BottomSheetBehavior_Layout_backgroundTint); @@ -1127,7 +1134,10 @@ private int calculatePeekHeight() { if (peekHeightAuto) { return Math.max(peekHeightMin, parentHeight - parentWidth * 9 / 16); } - return peekHeight + (gestureInsetBottomIgnored ? 0 : gestureInsetBottom); + if (!gestureInsetBottomIgnored && gestureInsetBottom > 0) { + return Math.max(peekHeight, gestureInsetBottom + peekHeightGestureInsetBuffer); + } + return peekHeight; } private void calculateCollapsedOffset() {