Skip to content


[BottomSheetBehavior] Fix for detached from bottom sheet behavior.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Material Design Team authored and drchen committed Apr 12, 2023
1 parent 7bc26e5 commit 9c4b73d
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -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);
Expand Down

0 comments on commit 9c4b73d

Please sign in to comment.