Commit 355fe634 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Fix blank navigation sheet bug

This CL fixes a bug that shows a blank navigation sheet when invoked
while other bottom sheet is visible. When it cannot be opened, it
removes itself from the bottom sheet queue to prevent it from showing
up later.

Bug: 1016750
Change-Id: I0f0cee5088832224706ea7b999e9843420bdc0a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875888Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709336}
parent 7db35036
......@@ -2270,14 +2270,17 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
mNavigationSheet = NavigationSheet.create(
getWindow().getDecorView().findViewById(android.R.id.content), this,
this::getBottomSheetController, new TabbedSheetDelegate(tab));
mNavigationSheet.startAndExpand(/* forward=*/false, /* animate=*/true);
getBottomSheet().addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetClosed(int reason) {
getBottomSheet().removeObserver(this);
mNavigationSheet = null;
}
});
if (!mNavigationSheet.startAndExpand(/* forward=*/false, /* animate=*/true)) {
mNavigationSheet = null;
} else {
getBottomSheet().addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetClosed(int reason) {
getBottomSheet().removeObserver(this);
mNavigationSheet = null;
}
});
}
}
@Override
......
......@@ -78,7 +78,12 @@ public interface NavigationSheet {
public void start(boolean forward, boolean showCloseIndicator) {}
@Override
public void startAndExpand(boolean forward, boolean animate) {}
public boolean startAndExpand(boolean forward, boolean animate) {
return false;
}
@Override
public void close(boolean animate) {}
@Override
public void onScroll(float delta, float overscroll, boolean willNavigate) {}
......@@ -109,8 +114,15 @@ public interface NavigationSheet {
* Fully expand the navigation sheet from the beginning.
* @param forward {@code true} if this is for forward navigation.
* @param animate {@code true} to enable animation.
* @return {@code true} if the sheet is opened as expected.
*/
boolean startAndExpand(boolean forward, boolean animate);
/**
* Close the navigation sheet.
* @param animate {@code true} to enable animation.
*/
void startAndExpand(boolean forward, boolean animate);
void close(boolean animate);
/**
* Process swipe gesture and update the navigation sheet state.
......
......@@ -149,18 +149,23 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
}
// Transition to either peeked or expanded state.
private void openSheet(boolean fullyExpand, boolean animate) {
private boolean openSheet(boolean fullyExpand, boolean animate) {
mContentView =
(NavigationSheetView) mLayoutInflater.inflate(R.layout.navigation_sheet, null);
ListView listview = (ListView) mContentView.findViewById(R.id.navigation_entries);
listview.setAdapter(mModelAdapter);
NavigationHistory history = mDelegate.getHistory(mForward);
mMediator.populateEntries(history);
mBottomSheetController.get().requestShowContent(this, true);
if (!mBottomSheetController.get().requestShowContent(this, true)) {
close(false);
mContentView = null;
return false;
}
mBottomSheetController.get().getBottomSheet().addObserver(mSheetObserver);
mSheetTriggered = true;
mFullyExpand = fullyExpand;
if (fullyExpand || history.getEntryCount() <= SKIP_PEEK_COUNT) expandSheet();
return true;
}
private void expandSheet() {
......@@ -179,9 +184,9 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
}
@Override
public void startAndExpand(boolean forward, boolean animate) {
public boolean startAndExpand(boolean forward, boolean animate) {
start(forward, /* showCloseIndicator= */ false);
openSheet(/* fullyExpand= */ true, animate);
return openSheet(/* fullyExpand= */ true, animate);
}
@Override
......@@ -218,11 +223,8 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
if (isPeeked()) expandSheet();
}
/**
* Hide the sheet and reset its model.
* @param animation {@code true} if animation effect is to be made.
*/
private void close(boolean animate) {
@Override
public void close(boolean animate) {
if (!isHidden()) mBottomSheetController.get().hideContent(this, animate);
mBottomSheetController.get().getBottomSheet().removeObserver(mSheetObserver);
mMediator.clear();
......
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