Fixed
Status Update
Comments
ti...@google.com <ti...@google.com>
co...@google.com <co...@google.com>
ma...@google.com <ma...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 9b4e7812393e3ed79b914f726c579cf158f5c42c
Author: Max Alfonso-Ying <maxying@google.com>
Date: Fri Jul 28 18:54:26 2023
[Menu] Use MenuPosition to implement DropdownMenuPositionProvider
Behavior should be the same except:
- offset.x uses LayoutDirection instead of whether the menu
is left- or right- aligned.
- offset.y is now always added instead of depending on whether
the menu is top- or bottom- aligned.
- Positioning w.r.t. the window better accounts for the anchor
position instead of always positioning at the bottom.
- Position "fallback" options are now the window-relative
positions instead of the anchor-relative ones.
Bug: b/294103942 , b/293137081
Test: updated MenuTest.kt
Relnote: "Fixed DropdownMenu's `offset` calculation so x offsets
depend solely on the local layout direction, and y offsets will no
longer be reversed when the menu is near the bottom of the screen."
Change-Id: Ib87a2157a9870409fdf066337c00585fd3ae005c
M compose/material3/material3/src/androidAndroidTest/kotlin/androidx/compose/material3/MenuTest.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/AndroidMenu.android.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt
M compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt
https://android-review.googlesource.com/2681138
Branch: androidx-main
commit 9b4e7812393e3ed79b914f726c579cf158f5c42c
Author: Max Alfonso-Ying <maxying@google.com>
Date: Fri Jul 28 18:54:26 2023
[Menu] Use MenuPosition to implement DropdownMenuPositionProvider
Behavior should be the same except:
- offset.x uses LayoutDirection instead of whether the menu
is left- or right- aligned.
- offset.y is now always added instead of depending on whether
the menu is top- or bottom- aligned.
- Positioning w.r.t. the window better accounts for the anchor
position instead of always positioning at the bottom.
- Position "fallback" options are now the window-relative
positions instead of the anchor-relative ones.
Bug:
Test: updated MenuTest.kt
Relnote: "Fixed DropdownMenu's `offset` calculation so x offsets
depend solely on the local layout direction, and y offsets will no
longer be reversed when the menu is near the bottom of the screen."
Change-Id: Ib87a2157a9870409fdf066337c00585fd3ae005c
M compose/material3/material3/src/androidAndroidTest/kotlin/androidx/compose/material3/MenuTest.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/AndroidMenu.android.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ExposedDropdownMenu.kt
M compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Menu.kt
ma...@google.com <ma...@google.com>
ja...@gmail.com <ja...@gmail.com> #3
This issue also present in androidx.compose.material package
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit cdd989b146a4758f9974b63c2e53e4eb767e961e
Author: Max Alfonso-Ying <maxying@google.com>
Date: Wed Aug 09 19:42:40 2023
[Menu] Fix offset calculations
Same logic as aosp/2681138, ported to the M2 version.
Bug: b/294103942 , b/293137081
Test: updated MenuTest.kt
Relnote: "Fixed DropdownMenu's `offset` calculation so x offsets
depend solely on the local layout direction, and y offsets will no
longer be reversed when the menu is near the bottom of the screen."
Change-Id: Iccc743f3306d9b259f0cc21d1089d9479df203fb
M compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt
M compose/material/material/src/androidMain/kotlin/androidx/compose/material/AndroidMenu.android.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/AndroidMenu.android.kt
https://android-review.googlesource.com/2701713
Branch: androidx-main
commit cdd989b146a4758f9974b63c2e53e4eb767e961e
Author: Max Alfonso-Ying <maxying@google.com>
Date: Wed Aug 09 19:42:40 2023
[Menu] Fix offset calculations
Same logic as aosp/2681138, ported to the M2 version.
Bug:
Test: updated MenuTest.kt
Relnote: "Fixed DropdownMenu's `offset` calculation so x offsets
depend solely on the local layout direction, and y offsets will no
longer be reversed when the menu is near the bottom of the screen."
Change-Id: Iccc743f3306d9b259f0cc21d1089d9479df203fb
M compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt
M compose/material/material/src/androidMain/kotlin/androidx/compose/material/AndroidMenu.android.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/AndroidMenu.android.kt
ma...@google.com <ma...@google.com>
vi...@gmail.com <vi...@gmail.com> #5
Since offset.y is now always added, what is the recommendation for handling the offset when the popup is top aligned? Is there a mechanism to know that so that I can apply a negative offset to shift it up?
Description
compose-bom = "2023.06.01"
compose-compiler = "1.5.1"
Jetpack Compose component(s) used:
DropdownMenu
Android Studio Build:
Android Studio Giraffe | 2022.3.1
Kotlin version:
1.9.0
Emulator version:
33.1.6
Emulated device:
Pixel 4 (33 api) + google services
Steps to Reproduce or Code Sample to Reproduce:
With i use y offset value from -127.dp to -231.dp DropdownMenu draw in incorrect location
Sample
```
import android.util.Log
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
@Composable
private fun Test() {
var expanded by remember {
mutableStateOf(false)
}
var yOffset by remember {
mutableStateOf((-125).dp)
}
Box(
modifier = Modifier
.fillMaxSize()
.clickable {
yOffset -= 1.dp
expanded = true
},
contentAlignment = Alignment.Center,
) {
Text(text = "Current offset: $yOffset")
val menuOffset = remember(yOffset) {
DpOffset(200.dp, yOffset).also {
Log.d("TestOffset", "OFFSET = $it")
}
}
DropdownMenu(
expanded = expanded,
offset = menuOffset,
onDismissRequest = { expanded = false },
) {
DropdownMenuItem(onClick = { /*TODO*/ }) {
Text(text = "Item 1")
}
DropdownMenuItem(onClick = { /*TODO*/ }) {
Text(text = "Item 2")
}
DropdownMenuItem(onClick = { /*TODO*/ }) {
Text(text = "Item 3")
}
}
}
}
@Preview
@Composable
fun TestPreview() {
Test()
}
```