Commit 1b3fbb49 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Bottom container listens to bottom sheet

The bottom container that hosts infobars and snackbars now listens to
the bottom sheet. This allows the bottom container to stack on top of
the sheet when it is showing.

Bug: 827541
Change-Id: Ib130cf4149223afc892945f84483467b88c28588
Reviewed-on: https://chromium-review.googlesource.com/988063Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547446}
parent 1abf8531
......@@ -1266,6 +1266,8 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
mBottomSheet = coordinator.findViewById(R.id.bottom_sheet);
mBottomSheet.init(coordinator, this);
((BottomContainer) findViewById(R.id.bottom_container)).setBottomSheet(mBottomSheet);
mFadingBackgroundView = (FadingBackgroundView) findViewById(R.id.fading_focus_target);
mBottomSheetController = new BottomSheetController(getTabModelSelector(),
getCompositorViewHolder().getLayoutManager(), mFadingBackgroundView,
......
......@@ -10,15 +10,23 @@ import android.widget.FrameLayout;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
/**
* The container that holds both infobars and snackbars. It will be translated up and down when the
* bottom controls' offset changes.
*/
public class BottomContainer extends FrameLayout implements FullscreenListener {
/** The {@link ChromeFullscreenManager} to listen for controls offset changes. */
private ChromeFullscreenManager mFullscreenManager;
/** The desired Y offset if unaffected by other UI. */
private float mBaseYOffset;
/** The offset generated by the {@link BottomSheet} showing. */
private float mOffsetFromSheet;
/**
* Constructor for XML inflation.
*/
......@@ -35,15 +43,44 @@ public class BottomContainer extends FrameLayout implements FullscreenListener {
setTranslationY(-fullscreenManager.getBottomControlsHeight());
}
// FullscreenListner methods
/**
* @param sheet The {@link BottomSheet} that interacts with this container.
*/
public void setBottomSheet(BottomSheet sheet) {
sheet.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetOffsetChanged(float heightFraction) {
// We only care about the height of the bottom sheet between its hidden and peeking
// state (the UI should stack). Once the sheet is opened, the bottom container
// stays in place, becoming obscured by the sheet.
if (heightFraction > sheet.getPeekRatio()) return;
mOffsetFromSheet = (sheet.getSheetContainerHeight() * heightFraction)
- sheet.getToolbarShadowHeight();
setTranslationY(mBaseYOffset);
}
});
}
// FullscreenListener methods
@Override
public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) {
setTranslationY(bottomOffset - mFullscreenManager.getBottomControlsHeight());
setTranslationY(mBaseYOffset);
}
@Override
public void setTranslationY(float y) {
mBaseYOffset = y;
float offsetFromControls = mFullscreenManager.getBottomControlOffset()
- mFullscreenManager.getBottomControlsHeight();
// Don't translate any lower than the bottom of the screen.
super.setTranslationY(Math.min(mBaseYOffset - (offsetFromControls + mOffsetFromSheet), 0));
}
@Override
public void onBottomControlsHeightChanged(int bottomControlsHeight) {
setTranslationY(-bottomControlsHeight);
setTranslationY(mBaseYOffset);
}
@Override
......
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