You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug 1854131 - Compare availableHeightToTop and availableHeightToBottom when positioning menu. r=android-reviewers,twhite
When the popup doesn't fit up or down, because both availableHeightToTop and availableHeightToBottom are both smaller than containerHeight choose the highest one to choose menu direction.
Differential Revision: https://phabricator.services.mozilla.com/D205207
Copy file name to clipboardExpand all lines: mobile/android/android-components/components/browser/menu/src/main/java/mozilla/components/browser/menu/BrowserMenuPositioning.kt
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -74,8 +74,8 @@ internal fun inferMenuPositioningData(
74
74
val (availableHeightToTop, availableHeightToBottom) = getMaxAvailableHeightToTopAndBottom(anchor)
75
75
val containerHeight = containerView.measuredHeight
76
76
77
-
val fitsUp = availableHeightToTop >= containerHeight
78
-
val fitsDown = availableHeightToBottom >= containerHeight
77
+
val fitsUp = availableHeightToTop >= containerHeight|| availableHeightToTop > availableHeightToBottom
78
+
val fitsDown = availableHeightToBottom >= containerHeight|| availableHeightToBottom > availableHeightToTop
Copy file name to clipboardExpand all lines: mobile/android/android-components/components/browser/menu/src/test/java/mozilla/components/browser/menu/BrowserMenuPositioningTest.kt
@@ -41,6 +43,61 @@ class BrowserMenuPositioningTest {
41
43
Assert.assertEquals(expected, result)
42
44
}
43
45
46
+
@Test
47
+
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`() {
fitsUp =false, // availableHeightToTop(0) is smaller than containerHeight(70) and smaller than availableHeightToBottom(50)
61
+
fitsDown =true, // availableHeightToBottom(50) is smaller than containerHeight(70) and bigger than availableHeightToTop(0)
62
+
availableHeightToTop =0,
63
+
availableHeightToBottom =50, // mocked by us above
64
+
containerViewHeight =70, // mocked by us above
65
+
)
66
+
Assert.assertEquals(expected, result)
67
+
}
68
+
69
+
@Test
70
+
fun`GIVEN inferMenuPositioningData WHEN availableHeightToTop is bigger than availableHeightToBottom THEN it returns a new MenuPositioningData populated with all data needed to show a PopupWindow that fits up`() {
fitsUp =true, // availableHeightToTop(60) is smaller than containerHeight(70) and bigger than availableHeightToBottom(40)
92
+
fitsDown =false, // availableHeightToBottom(40) is smaller than containerHeight(70) and smaller than availableHeightToTop(60)
93
+
availableHeightToTop =60, // mocked by us above
94
+
availableHeightToBottom =40,
95
+
containerViewHeight =70, // mocked by us above
96
+
)
97
+
98
+
Assert.assertEquals(expected, result)
99
+
}
100
+
44
101
@Test
45
102
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`() {
0 commit comments