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.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
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 = {
|
||||
state.roomState.takeIfContent()?.let {
|
||||
OverflowMenu {
|
||||
when (it.isMuted) {
|
||||
true -> DropdownMenuItem(text = { Text("Unmute notifications", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
||||
viewModel.dispatch(ScreenAction.Notifications.Unmute)
|
||||
})
|
||||
|
||||
false -> DropdownMenuItem(text = { Text("Mute notifications", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
||||
viewModel.dispatch(ScreenAction.Notifications.Mute)
|
||||
})
|
||||
BooleanOption(value = it.isMuted, trueText = "Unmute notifications", falseText = "Mute notifications") {
|
||||
val action = when (it) {
|
||||
true -> ScreenAction.Notifications.Unmute
|
||||
false -> ScreenAction.Notifications.Unmute
|
||||
}
|
||||
viewModel.dispatch(action)
|
||||
}
|
||||
DropdownMenuItem(text = { Text("Leave room", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {
|
||||
viewModel.dispatch(ScreenAction.LeaveRoom)
|
||||
|
|
Loading…
Reference in New Issue