Commit cb0e3caa authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][BottomSheet] Fix bottom sheet is positioned on top

This CL fixes the bug that bottom sheet is sometimes positioned on the
top of the screen because the argument width is 0.

Bug: 1146429, 1143637
Change-Id: Ic2bc823139b9f5bcd2fcfed435d221a210bde092
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526347Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827210}
parent c7913a8a
......@@ -111,6 +111,9 @@ class BottomSheet extends FrameLayout
/** The height of the view that contains the bottom sheet. */
private int mContainerHeight;
/** The width of the bottom sheet content view. */
private int mContentWidth;
/** The desired height of the current content view. */
private float mContentDesiredHeight = HEIGHT_UNSPECIFIED;
......@@ -322,6 +325,8 @@ class BottomSheet extends FrameLayout
mContainerHeight = root.getHeight();
mScrollableHeight = mContainerHeight + mToolbarShadowHeight;
mContentWidth = mContainerWidth;
// Listen to height changes on the root.
root.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
private int mPreviousKeyboardHeight;
......@@ -337,6 +342,10 @@ class BottomSheet extends FrameLayout
mContainerHeight = bottom - top;
mScrollableHeight = mContainerHeight + mToolbarShadowHeight;
// TODO(https://crbug.com/1148421): Remove this update once we can handle
// mContentWidth update in onContentSizeChanged
mContentWidth = mContainerWidth;
if (previousWidth != mContainerWidth || previousHeight != mContainerHeight) {
if (mCurrentState == SheetState.HALF && !isHalfStateEnabled()) {
setSheetState(SheetState.FULL, false);
......@@ -1039,10 +1048,8 @@ class BottomSheet extends FrameLayout
if (mContentDesiredHeight != HEIGHT_UNSPECIFIED) {
return;
}
mSheetContent.getContentView().measure(
MeasureSpec.makeMeasureSpec(
mBottomSheetContentContainer.getMeasuredWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mContentWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(getMaxContentHeight(), MeasureSpec.AT_MOST));
mContentDesiredHeight = mSheetContent.getContentView().getMeasuredHeight();
}
......@@ -1252,6 +1259,9 @@ class BottomSheet extends FrameLayout
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom) {
// When there is a device rotation, mContentWidth needs to be updated before the new
// view is drawn.
mContentWidth = right - left;
invalidateContentDesiredHeight();
ensureContentIsWrapped(/* animate= */ true);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment