Код: Выделить всё
@Composable
private fun Actions() {
Row {
// More
var showMore by rememberState(initial = false)
IconButton(onClick = {showMore = true} )
{
Icon(imageVector = Icons.Outlined.MoreVert, contentDescription = null)
DropdownMenu(expanded = showMore, onDismissRequest = { showMore = false }
) {
Column {
Composable1
Composable2
Composable3
Composable4
}
}
}
}
}
Код: Выделить всё
What i need is changing the value of the variable showMore to "false" when the user clicks on one of the Composable in the column. I also tried putting the variable in a viewModel, so to change its value when the user is in the Composable, with a similar code (obviously changing the previous code so to collect the state of the variable from the view model and change it with the two functions):
Код: Выделить всё
var showMenuMore by mutableStateOf(false)
private set
fun showMenuMoreOpen() {
showMenuMore = true
}
fun showMenuMoreClose() {
showMenuMore = false
}
Спасибо за вашу помощь.
Изменить.
Я думал о другом (без использования модели представления). .
Я мог бы изменить значение «var showMore» с помощью SideEffect (или LaunchedEffect с Unit в качестве ключа) в составных объектах с 1 до 4, но эта переменная недоступна за пределами составных элементов (Действия). Есть ли способ сделать его доступным?
Подробнее здесь: https://stackoverflow.com/questions/790 ... composable