Alexander Maryanovsky
01/15/2024, 11:50 AMDropdownMenu
behaves), but during that time, because the box content changed, the menu items are recomposed according to the new content.Alexander Maryanovsky
01/15/2024, 11:52 AMfun main() = singleWindowApplication {
var flag by remember { mutableStateOf(false) }
val dropdownMenuState = remember { DropdownMenuState() }
Box(
modifier = Modifier
.fillMaxSize()
.contextMenuOpenDetector(dropdownMenuState)
) {
DropdownMenu(
state = dropdownMenuState,
modifier = Modifier
.background(Color.White)
) {
@Composable
fun menuItem(text: String, onClick: () -> Unit) {
DropdownMenuItem(
onClick = {
onClick()
dropdownMenuState.status = DropdownMenuState.Status.Closed
}
) {
Text(text)
}
}
if (flag) {
menuItem("Item 1") { flag = false }
menuItem("Item 2") { flag = false }
menuItem("Item 3") { flag = false }
menuItem("Item 4") { flag = false }
menuItem("Item 5") { flag = false }
}
else {
menuItem("Item 1") { flag = true }
}
}
}
}
shikasd
01/15/2024, 1:54 PMshikasd
01/15/2024, 1:55 PMAlexander Maryanovsky
01/15/2024, 1:56 PMshikasd
01/15/2024, 1:57 PMshikasd
01/15/2024, 1:58 PMAlexander Maryanovsky
01/15/2024, 1:58 PMdrawWithCache
maybe.shikasd
01/15/2024, 2:00 PMshikasd
01/15/2024, 2:00 PMAlexander Maryanovsky
01/15/2024, 6:00 PMRadoslaw Juszczyk
01/16/2024, 7:23 AMdelay(200)
.
In a perfect world DropdownMenuState
would have a suspending function suspend fun animateToStatus(status: DropdownMenuState.Status)
and you could suspend until the animation is done and then change the underlying flag
Alexander Maryanovsky
01/16/2024, 7:42 AM