From 9c4b73da3a040003bae3167e9ae91f4d0cc0a9f7 Mon Sep 17 00:00:00 2001 From: Material Design Team Date: Mon, 10 Apr 2023 08:50:21 -0700 Subject: [PATCH] [BottomSheetBehavior] Fix for detached from bottom sheet behavior. When max height of BottomSheetBehavior is specified the calculations of top inset do not account for the max height parameter and may override internal `childHeight` variable used for inset calculation with parentHeight. This may cause top inset to be too small and end up letting BottomSheetBehavior content be scrolled above bottom of the screen (the content might end up "floating" above the bottom of the screen). The CL ensures that overridden `childHeight` is coerced to a min value of parent or maxHeight parameter in cases when maxHeight was set. PiperOrigin-RevId: 523126749 --- .../android/material/bottomsheet/BottomSheetBehavior.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java index 749a364bd1d..64131ec780f 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -577,11 +577,12 @@ public boolean onLayoutChild( if (parentHeight - childHeight < insetTop) { if (paddingTopSystemWindowInsets) { // If the bottomsheet would land in the middle of the status bar when fully expanded add - // extra space to make sure it goes all the way. - childHeight = parentHeight; + // extra space to make sure it goes all the way up or up to max height if it is specified. + childHeight = (maxHeight == NO_MAX_SIZE) ? parentHeight : min(parentHeight, maxHeight); } else { // If we don't want the bottomsheet to go under the status bar we cap its height - childHeight = parentHeight - insetTop; + int insetHeight = parentHeight - insetTop; + childHeight = (maxHeight == NO_MAX_SIZE) ? insetHeight : min(insetHeight, maxHeight); } } fitToContentsOffset = max(0, parentHeight - childHeight);