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 ...@@ -2270,14 +2270,17 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
mNavigationSheet = NavigationSheet.create( mNavigationSheet = NavigationSheet.create(
getWindow().getDecorView().findViewById(android.R.id.content), this, getWindow().getDecorView().findViewById(android.R.id.content), this,
this::getBottomSheetController, new TabbedSheetDelegate(tab)); this::getBottomSheetController, new TabbedSheetDelegate(tab));
mNavigationSheet.startAndExpand(/* forward=*/false, /* animate=*/true); if (!mNavigationSheet.startAndExpand(/* forward=*/false, /* animate=*/true)) {
getBottomSheet().addObserver(new EmptyBottomSheetObserver() { mNavigationSheet = null;
@Override } else {
public void onSheetClosed(int reason) { getBottomSheet().addObserver(new EmptyBottomSheetObserver() {
getBottomSheet().removeObserver(this); @Override
mNavigationSheet = null; public void onSheetClosed(int reason) {
} getBottomSheet().removeObserver(this);
}); mNavigationSheet = null;
}
});
}
} }
@Override @Override
......
...@@ -78,7 +78,12 @@ public interface NavigationSheet { ...@@ -78,7 +78,12 @@ public interface NavigationSheet {
public void start(boolean forward, boolean showCloseIndicator) {} public void start(boolean forward, boolean showCloseIndicator) {}
@Override @Override
public void startAndExpand(boolean forward, boolean animate) {} public boolean startAndExpand(boolean forward, boolean animate) {
return false;
}
@Override
public void close(boolean animate) {}
@Override @Override
public void onScroll(float delta, float overscroll, boolean willNavigate) {} public void onScroll(float delta, float overscroll, boolean willNavigate) {}
...@@ -109,8 +114,15 @@ public interface NavigationSheet { ...@@ -109,8 +114,15 @@ public interface NavigationSheet {
* Fully expand the navigation sheet from the beginning. * Fully expand the navigation sheet from the beginning.
* @param forward {@code true} if this is for forward navigation. * @param forward {@code true} if this is for forward navigation.
* @param animate {@code true} to enable animation. * @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. * Process swipe gesture and update the navigation sheet state.
......
...@@ -149,18 +149,23 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -149,18 +149,23 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
} }
// Transition to either peeked or expanded state. // Transition to either peeked or expanded state.
private void openSheet(boolean fullyExpand, boolean animate) { private boolean openSheet(boolean fullyExpand, boolean animate) {
mContentView = mContentView =
(NavigationSheetView) mLayoutInflater.inflate(R.layout.navigation_sheet, null); (NavigationSheetView) mLayoutInflater.inflate(R.layout.navigation_sheet, null);
ListView listview = (ListView) mContentView.findViewById(R.id.navigation_entries); ListView listview = (ListView) mContentView.findViewById(R.id.navigation_entries);
listview.setAdapter(mModelAdapter); listview.setAdapter(mModelAdapter);
NavigationHistory history = mDelegate.getHistory(mForward); NavigationHistory history = mDelegate.getHistory(mForward);
mMediator.populateEntries(history); 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); mBottomSheetController.get().getBottomSheet().addObserver(mSheetObserver);
mSheetTriggered = true; mSheetTriggered = true;
mFullyExpand = fullyExpand; mFullyExpand = fullyExpand;
if (fullyExpand || history.getEntryCount() <= SKIP_PEEK_COUNT) expandSheet(); if (fullyExpand || history.getEntryCount() <= SKIP_PEEK_COUNT) expandSheet();
return true;
} }
private void expandSheet() { private void expandSheet() {
...@@ -179,9 +184,9 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -179,9 +184,9 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
} }
@Override @Override
public void startAndExpand(boolean forward, boolean animate) { public boolean startAndExpand(boolean forward, boolean animate) {
start(forward, /* showCloseIndicator= */ false); start(forward, /* showCloseIndicator= */ false);
openSheet(/* fullyExpand= */ true, animate); return openSheet(/* fullyExpand= */ true, animate);
} }
@Override @Override
...@@ -218,11 +223,8 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -218,11 +223,8 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
if (isPeeked()) expandSheet(); if (isPeeked()) expandSheet();
} }
/** @Override
* Hide the sheet and reset its model. public void close(boolean animate) {
* @param animation {@code true} if animation effect is to be made.
*/
private void close(boolean animate) {
if (!isHidden()) mBottomSheetController.get().hideContent(this, animate); if (!isHidden()) mBottomSheetController.get().hideContent(this, animate);
mBottomSheetController.get().getBottomSheet().removeObserver(mSheetObserver); mBottomSheetController.get().getBottomSheet().removeObserver(mSheetObserver);
mMediator.clear(); 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