Commit 2e3396c2 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Attach the BottomSheet to the hierarchy before opening

This patch attaches the BottomSheet to the view hierarchy immediately
upon showing a new content view. This gives the new content view the
opportunity to do layout before being shown.

Bug: 1113857
Change-Id: I6a329782f941c088b1dbee30c30982482e228561
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343315Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797223}
parent 1b2da123
......@@ -17,6 +17,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilKeyboardMatchesCondition;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewAssertionTrue;
......@@ -336,7 +337,7 @@ public class AutofillAssistantChromeTabIntegrationTest {
// Clicking location bar hides UI and shows the keyboard.
onView(withId(org.chromium.chrome.R.id.url_bar)).perform(click());
waitUntilViewAssertionTrue(withText("Prompt"), doesNotExist(), DEFAULT_MAX_TIME_TO_POLL);
waitUntilViewMatchesCondition(withText("Prompt"), not(isCompletelyDisplayed()));
waitUntilKeyboardMatchesCondition(mTestRule, /* isShowing= */ true);
// Closing keyboard brings it back.
......
......@@ -494,6 +494,16 @@ class BottomSheet extends FrameLayout
mSheetContent.getContentView().removeOnLayoutChangeListener(this);
}
if (content != null && getParent() == null) {
mSheetContainer.addView(this);
} else if (content == null) {
if (mSheetContainer.getParent() == null) {
throw new RuntimeException(
"Attempting to detach sheet that was not in the hierarchy!");
}
mSheetContainer.removeView(this);
}
swapViews(content != null ? content.getContentView() : null,
mSheetContent != null ? mSheetContent.getContentView() : null,
mBottomSheetContentContainer);
......@@ -625,13 +635,6 @@ class BottomSheet extends FrameLayout
setTranslationY(translationY);
float hiddenHeight = getHiddenRatio() * mContainerHeight;
if (mCurrentOffsetPx <= hiddenHeight && this.getParent() != null) {
mSheetContainer.removeView(this);
} else if (mCurrentOffsetPx > hiddenHeight && this.getParent() == null) {
mSheetContainer.addView(this);
}
// Do open/close computation based on the minimum allowed state by the sheet's content.
// Note that when transitioning from hidden to peek, even dismissable sheets may want
// to have a peek state.
......
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