From 20b0c79959821b54e36253ed471e9c03794853d3 Mon Sep 17 00:00:00 2001 From: Adriana Maries Date: Tue, 20 Feb 2024 10:40:26 +0200 Subject: [PATCH] Bug 1854131 - Three-dot main menu falls off screen, disappears in landscape mode The popup doesn't fits up or fits down, because both availableHeightToTop and availableHeightToBottom are smaller than containerHeight. Because of this the popup is not displayed. As the popup is scrollable we should display it where the height is bigger (top or bottom). --- .../browser/menu/BrowserMenuPositioning.kt | 4 ++-- .../menu/BrowserMenuPositioningTest.kt | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/android-components/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenuPositioning.kt b/android-components/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenuPositioning.kt index 480fa2c32345..b6bce41f6b74 100644 --- a/android-components/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenuPositioning.kt +++ b/android-components/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenuPositioning.kt @@ -74,8 +74,8 @@ internal fun inferMenuPositioningData( val (availableHeightToTop, availableHeightToBottom) = getMaxAvailableHeightToTopAndBottom(anchor) val containerHeight = containerView.measuredHeight - val fitsUp = availableHeightToTop >= containerHeight - val fitsDown = availableHeightToBottom >= containerHeight + val fitsUp = availableHeightToTop >= containerHeight || availableHeightToTop > availableHeightToBottom + val fitsDown = availableHeightToBottom >= containerHeight || availableHeightToBottom > availableHeightToTop return inferMenuPosition( anchor, diff --git a/android-components/components/browser/menu/src/test/java/mozilla/components/browser/menu/BrowserMenuPositioningTest.kt b/android-components/components/browser/menu/src/test/java/mozilla/components/browser/menu/BrowserMenuPositioningTest.kt index 42ce169281f9..be922b5cb5b2 100644 --- a/android-components/components/browser/menu/src/test/java/mozilla/components/browser/menu/BrowserMenuPositioningTest.kt +++ b/android-components/components/browser/menu/src/test/java/mozilla/components/browser/menu/BrowserMenuPositioningTest.kt @@ -41,6 +41,29 @@ class BrowserMenuPositioningTest { Assert.assertEquals(expected, result) } + @Test + fun `GIVEN inferMenuPositioningData WHEN availableHeightToBottom is bigger than availableHeightToTop THEN it returns a new MenuPositioningData populated with all data needed to show a PopupWindow that fits down`() { + val view: ViewGroup = mock() + Mockito.doReturn(70).`when`(view).measuredHeight + val anchor = View(testContext) + anchor.layoutParams = ViewGroup.LayoutParams(20, 40) + + setScreenHeight(50) + + val result = inferMenuPositioningData(view, anchor, MenuPositioningData()) + + val expected = MenuPositioningData( + BrowserMenuPlacement.AnchoredToTop.Dropdown(anchor), // orientation DOWN and fitsDown + askedOrientation = BrowserMenu.Orientation.DOWN, // default + fitsUp = false, // availableHeightToTop(0) is smaller than containerHeight(70) and smaller than availableHeightToBottom(50) + fitsDown = true, // availableHeightToBottom(50) is smaller than containerHeight(70) and bigger than availableHeightToTop(0) + availableHeightToTop = 0, + availableHeightToBottom = 50, // mocked by us above + containerViewHeight = 70, // mocked by us above + ) + Assert.assertEquals(expected, result) + } + @Test fun `GIVEN inferMenuPosition WHEN called with an anchor and the current menu data THEN it returns a new MenuPositioningData with data about positioning the menu`() { val view: View = mock()