Commit c35f4bc4 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Fix more issues with scrim and bottom sheet

This patch removes a check that causes the scrim to remain visable
after the bottom sheet is closed. The check in question blocked offset
change events if the bottom sheet is closed, but in certain cases like
when the sheet doesn't animate, the sheets state is closed before any
offset events occur.

This patch also adds a BottomSheetObserver when the sheet is opened
that controls the opacity of the scrim and removes it when the sheet
is closed.

Bug: 842902,842765
Change-Id: Ic70532cefa0ddcafc06d0a2b3a5b6e28639ff24e
Reviewed-on: https://chromium-review.googlesource.com/1058437
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558814}
parent 6fbb920f
...@@ -164,6 +164,14 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis ...@@ -164,6 +164,14 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis
} }
}); });
final BottomSheetObserver scrimAlphaSheetObserver = new EmptyBottomSheetObserver() {
@Override
public void onTransitionPeekToHalf(float transitionFraction) {
fadingBackgroundView.setViewAlpha(transitionFraction);
}
};
// Handles attaching the observer that controls the placement and visibility of the scrim.
mBottomSheet.addObserver(new EmptyBottomSheetObserver() { mBottomSheet.addObserver(new EmptyBottomSheetObserver() {
/** /**
* The index of the scrim in the view hierarchy prior to being moved for the bottom * The index of the scrim in the view hierarchy prior to being moved for the bottom
...@@ -171,14 +179,9 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis ...@@ -171,14 +179,9 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis
*/ */
private int mOriginalScrimIndexInParent; private int mOriginalScrimIndexInParent;
@Override
public void onTransitionPeekToHalf(float transitionFraction) {
if (!mBottomSheet.isSheetOpen()) return;
fadingBackgroundView.setViewAlpha(transitionFraction);
}
@Override @Override
public void onSheetOpened(@BottomSheet.StateChangeReason int reason) { public void onSheetOpened(@BottomSheet.StateChangeReason int reason) {
mBottomSheet.addObserver(scrimAlphaSheetObserver);
mOriginalScrimIndexInParent = UiUtils.getChildIndexInParent(fadingBackgroundView); mOriginalScrimIndexInParent = UiUtils.getChildIndexInParent(fadingBackgroundView);
ViewGroup parent = (ViewGroup) fadingBackgroundView.getParent(); ViewGroup parent = (ViewGroup) fadingBackgroundView.getParent();
UiUtils.removeViewFromParent(fadingBackgroundView); UiUtils.removeViewFromParent(fadingBackgroundView);
...@@ -187,10 +190,12 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis ...@@ -187,10 +190,12 @@ public class BottomSheetController implements ApplicationStatus.ActivityStateLis
@Override @Override
public void onSheetClosed(@BottomSheet.StateChangeReason int reason) { public void onSheetClosed(@BottomSheet.StateChangeReason int reason) {
mBottomSheet.removeObserver(scrimAlphaSheetObserver);
assert mOriginalScrimIndexInParent >= 0; assert mOriginalScrimIndexInParent >= 0;
ViewGroup parent = (ViewGroup) fadingBackgroundView.getParent(); ViewGroup parent = (ViewGroup) fadingBackgroundView.getParent();
UiUtils.removeViewFromParent(fadingBackgroundView); UiUtils.removeViewFromParent(fadingBackgroundView);
parent.addView(fadingBackgroundView, mOriginalScrimIndexInParent); parent.addView(fadingBackgroundView, mOriginalScrimIndexInParent);
fadingBackgroundView.setViewAlpha(0);
} }
@Override @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