Make chat toolbar a bit more modular
This commit is contained in:
parent
ea2dd98e85
commit
5ab88d9063
2 changed files with 44 additions and 28 deletions
|
@ -261,7 +261,7 @@ fun ChatScreenContent(
|
|||
) {
|
||||
ChatToolBar(
|
||||
canSend = (chatComposerState.composerValue.isNotBlank() || uiState.lastResponseError != null) && !uiState.requestInProgress,
|
||||
canRestart = chatComposerState.composerValue.isBlank() && uiState.lastResponseError != null,
|
||||
willRestart = chatComposerState.composerValue.isBlank() && uiState.lastResponseError != null,
|
||||
onSend = onSend,
|
||||
onEmptySpaceClick = onRequestFocus
|
||||
)
|
||||
|
|
|
@ -26,17 +26,10 @@ import eu.m724.chatapp.R
|
|||
fun ChatToolBar(
|
||||
modifier: Modifier = Modifier,
|
||||
canSend: Boolean,
|
||||
canRestart: Boolean,
|
||||
willRestart: Boolean,
|
||||
onSend: () -> Unit,
|
||||
onEmptySpaceClick: () -> Unit
|
||||
) {
|
||||
val sendButtonColor by animateColorAsState(
|
||||
targetValue = if (canSend) {
|
||||
IconButtonDefaults.iconButtonColors().contentColor
|
||||
} else {
|
||||
IconButtonDefaults.iconButtonColors().disabledContentColor
|
||||
}, label = "sendButtonColor"
|
||||
)
|
||||
|
||||
ElevatedCard(
|
||||
modifier = modifier,
|
||||
|
@ -48,29 +41,52 @@ fun ChatToolBar(
|
|||
.clickable(onClick = onEmptySpaceClick),
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSend,
|
||||
SendMessageButton(
|
||||
modifier = Modifier
|
||||
.height(48.dp)
|
||||
.padding(horizontal = 8.dp),
|
||||
onClick = onSend,
|
||||
enabled = canSend,
|
||||
colors = IconButtonDefaults.iconButtonColors(
|
||||
contentColor = sendButtonColor,
|
||||
disabledContentColor = sendButtonColor
|
||||
)
|
||||
) {
|
||||
if (canRestart) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.outline_restart_alt_24),
|
||||
contentDescription = stringResource(R.string.button_send_restart_icon_description)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.Send,
|
||||
contentDescription = stringResource(R.string.button_send_icon_description)
|
||||
)
|
||||
}
|
||||
}
|
||||
willRestart = willRestart
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SendMessageButton(
|
||||
onClick: () -> Unit,
|
||||
willRestart: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
val color by animateColorAsState(
|
||||
targetValue = if (enabled) {
|
||||
IconButtonDefaults.iconButtonColors().contentColor
|
||||
} else {
|
||||
IconButtonDefaults.iconButtonColors().disabledContentColor
|
||||
}, label = "sendButtonColor"
|
||||
)
|
||||
|
||||
IconButton(
|
||||
onClick = onClick,
|
||||
modifier = modifier,
|
||||
enabled = enabled,
|
||||
colors = IconButtonDefaults.iconButtonColors(
|
||||
contentColor = color,
|
||||
disabledContentColor = color
|
||||
)
|
||||
) {
|
||||
if (willRestart) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.outline_restart_alt_24),
|
||||
contentDescription = stringResource(R.string.button_send_restart_icon_description)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.Send,
|
||||
contentDescription = stringResource(R.string.button_send_icon_description)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue