Commit 5fbb6b8c authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Fix triggering logic for BottomSheet's onSheetOpened

This patch fixes some broken assumptions with the triggering logic for
onSheetOpened and onSheetClosed. Now the checks for the current state
explicitly check if the state is considered opened or closed.

Change-Id: I86be48e93450074ed5171a9d1919dc973451d20b
Reviewed-on: https://chromium-review.googlesource.com/998519Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549198}
parent 0c939c0d
......@@ -1258,6 +1258,8 @@ public class BottomSheet extends FrameLayout
return;
}
@SheetState
final int previousState = mCurrentState;
mCurrentState = state;
if (mCurrentState == SHEET_STATE_HALF || mCurrentState == SHEET_STATE_FULL) {
......@@ -1280,13 +1282,31 @@ public class BottomSheet extends FrameLayout
o.onSheetStateChanged(mCurrentState);
}
if (state <= SHEET_STATE_PEEK) {
if (isSheetOpen() && isClosedState(getSheetState())) {
onSheetClosed(reason);
} else {
} else if (!isSheetOpen() && isClosedState(previousState)
&& isOpenedState(getSheetState())) {
onSheetOpened(reason);
}
}
/**
* @param state A state of the {@link BottomSheet}.
* @return Whether the provided state is considered open.
*/
private boolean isOpenedState(@SheetState int state) {
return state == SHEET_STATE_HALF || state == SHEET_STATE_FULL
|| state == SHEET_STATE_SCROLLING;
}
/**
* @param state A state of the {@link BottomSheet}.
* @return Whether the provided state is considered closed.
*/
private boolean isClosedState(@SheetState int state) {
return state == SHEET_STATE_PEEK || state == SHEET_STATE_HIDDEN;
}
/**
* If the animation to settle the sheet in one of its states is running.
* @return True if the animation is running.
......
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