Rename some variables for clarity.
Test: n/a
Change-Id: I14fffae026a96982fefe452e7326528a027214e2
diff --git a/compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt b/compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt
index b863609..53a02e7 100644
--- a/compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt
+++ b/compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt
@@ -122,12 +122,8 @@
onGloballyPositioned {
width = it.size.width
coordinates.value = it
- updateHeight(
- view.rootView,
- coordinates.value,
- verticalMarginInPx
- ) { newHeight ->
- menuHeight = newHeight
+ updateHeight(view.rootView, coordinates.value, verticalMarginInPx) {
+ newHeight -> menuHeight = newHeight
}
}.expandable(
expanded = expanded,
@@ -1044,18 +1040,18 @@
private fun updateHeight(
view: View,
- coordinates: LayoutCoordinates?,
+ anchorCoordinates: LayoutCoordinates?,
verticalMarginInPx: Int,
onHeightUpdate: (Int) -> Unit
) {
- coordinates ?: return
+ anchorCoordinates ?: return
val visibleWindowBounds = Rect().let {
view.getWindowVisibleDisplayFrame(it)
it
}
- val heightAbove = coordinates.boundsInWindow().top - visibleWindowBounds.top
- val heightBelow =
- visibleWindowBounds.bottom - visibleWindowBounds.top - coordinates.boundsInWindow().bottom
+ val heightAbove = anchorCoordinates.boundsInWindow().top - visibleWindowBounds.top
+ val heightBelow = visibleWindowBounds.bottom - visibleWindowBounds.top -
+ anchorCoordinates.boundsInWindow().bottom
onHeightUpdate(max(heightAbove, heightBelow).toInt() - verticalMarginInPx)
}
diff --git a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt
index 318985d..5d3822d 100644
--- a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt
+++ b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt
@@ -305,7 +305,7 @@
internal data class DropdownMenuPositionProvider(
val contentOffset: DpOffset,
val density: Density,
- val onPositionCalculated: (IntRect, IntRect) -> Unit = { _, _ -> }
+ val onPositionCalculated: (anchorBounds: IntRect, menuBounds: IntRect) -> Unit = { _, _ -> }
) : PopupPositionProvider {
override fun calculatePosition(
anchorBounds: IntRect,
@@ -319,40 +319,45 @@
val contentOffsetX = with(density) { contentOffset.x.roundToPx() }
val contentOffsetY = with(density) { contentOffset.y.roundToPx() }
- // Compute horizontal position.
- val toRight = anchorBounds.left + contentOffsetX
- val toLeft = anchorBounds.right - contentOffsetX - popupContentSize.width
- val toDisplayRight = windowSize.width - popupContentSize.width
- val toDisplayLeft = 0
+ // Compute menu horizontal position.
+ val leftToAnchorLeft = anchorBounds.left + contentOffsetX
+ val rightToAnchorRight = anchorBounds.right - contentOffsetX - popupContentSize.width
+ val leftToWindowLeft = 0
+ val rightToWindowRight = windowSize.width - popupContentSize.width
val x = if (layoutDirection == LayoutDirection.Ltr) {
sequenceOf(
- toRight,
- toLeft,
+ leftToAnchorLeft,
+ rightToAnchorRight,
// If the anchor gets outside of the window on the left, we want to position
- // toDisplayLeft for proximity to the anchor. Otherwise, toDisplayRight.
- if (anchorBounds.left >= 0) toDisplayRight else toDisplayLeft
+ // `leftToWindowLeft` for proximity to the anchor. Otherwise, `rightToWindowRight`.
+ if (anchorBounds.left < 0) leftToWindowLeft else rightToWindowRight
)
} else {
sequenceOf(
- toLeft,
- toRight,
+ rightToAnchorRight,
+ leftToAnchorLeft,
// If the anchor gets outside of the window on the right, we want to position
- // toDisplayRight for proximity to the anchor. Otherwise, toDisplayLeft.
- if (anchorBounds.right <= windowSize.width) toDisplayLeft else toDisplayRight
+ // `rightToWindowRight` for proximity to the anchor. Otherwise, `leftToWindowLeft`.
+ if (anchorBounds.right > windowSize.width) rightToWindowRight else leftToWindowLeft
)
}.firstOrNull {
it >= 0 && it + popupContentSize.width <= windowSize.width
- } ?: toLeft
+ } ?: rightToAnchorRight
- // Compute vertical position.
- val toBottom = maxOf(anchorBounds.bottom + contentOffsetY, verticalMargin)
- val toTop = anchorBounds.top - contentOffsetY - popupContentSize.height
- val toCenter = anchorBounds.top - popupContentSize.height / 2
- val toDisplayBottom = windowSize.height - popupContentSize.height - verticalMargin
- val y = sequenceOf(toBottom, toTop, toCenter, toDisplayBottom).firstOrNull {
+ // Compute menu vertical position.
+ val topToAnchorBottom = maxOf(anchorBounds.bottom + contentOffsetY, verticalMargin)
+ val bottomToAnchorTop = anchorBounds.top - contentOffsetY - popupContentSize.height
+ val centerToAnchorTop = anchorBounds.top - popupContentSize.height / 2
+ val bottomToWindowBottom = windowSize.height - popupContentSize.height - verticalMargin
+ val y = sequenceOf(
+ topToAnchorBottom,
+ bottomToAnchorTop,
+ centerToAnchorTop,
+ bottomToWindowBottom
+ ).firstOrNull {
it >= verticalMargin &&
it + popupContentSize.height <= windowSize.height - verticalMargin
- } ?: toTop
+ } ?: bottomToAnchorTop
onPositionCalculated(
anchorBounds,