Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1854131 - Three-dot main menu falls off screen, disappears in lan…
Browse files Browse the repository at this point in the history
…dscape 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).
  • Loading branch information
AdrianaMaries committed Feb 21, 2024
1 parent e5a9344 commit 20b0c79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 20b0c79

Please sign in to comment.