Create reusable dropdown option
This commit is contained in:
parent
408513764c
commit
0abac7c551
|
@ -4,10 +4,7 @@ import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.MoreVert
|
import androidx.compose.material.icons.outlined.MoreVert
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.DpOffset
|
import androidx.compose.ui.unit.DpOffset
|
||||||
|
@ -36,3 +33,12 @@ fun OverflowMenu(content: @Composable () -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BooleanOption(value: Boolean, trueText: String, falseText: String, onClick: (Boolean) -> Unit) {
|
||||||
|
val itemTextColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
|
when (value) {
|
||||||
|
true -> DropdownMenuItem(text = { Text(trueText, color = itemTextColor) }, onClick = { onClick(true) })
|
||||||
|
false -> DropdownMenuItem(text = { Text(falseText, color = itemTextColor) }, onClick = { onClick(false) })
|
||||||
|
}
|
||||||
|
}
|
|
@ -113,14 +113,12 @@ internal fun MessengerScreen(
|
||||||
Toolbar(onNavigate = { navigator.navigate.upToHome() }, roomTitle, actions = {
|
Toolbar(onNavigate = { navigator.navigate.upToHome() }, roomTitle, actions = {
|
||||||
state.roomState.takeIfContent()?.let {
|
state.roomState.takeIfContent()?.let {
|
||||||
OverflowMenu {
|
OverflowMenu {
|
||||||
when (it.isMuted) {
|
BooleanOption(value = it.isMuted, trueText = "Unmute notifications", falseText = "Mute notifications") {
|
||||||
true -> DropdownMenuItem(text = { Text("Unmute notifications", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
val action = when (it) {
|
||||||
viewModel.dispatch(ScreenAction.Notifications.Unmute)
|
true -> ScreenAction.Notifications.Unmute
|
||||||
})
|
false -> ScreenAction.Notifications.Unmute
|
||||||
|
}
|
||||||
false -> DropdownMenuItem(text = { Text("Mute notifications", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
viewModel.dispatch(action)
|
||||||
viewModel.dispatch(ScreenAction.Notifications.Mute)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
DropdownMenuItem(text = { Text("Leave room", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
DropdownMenuItem(text = { Text("Leave room", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
||||||
viewModel.dispatch(ScreenAction.LeaveRoom)
|
viewModel.dispatch(ScreenAction.LeaveRoom)
|
||||||
|
|
Loading…
Reference in New Issue