mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-06 16:43:43 +00:00
Tweak some UserStatusView ui
This commit is contained in:
+36
-23
@@ -10,8 +10,10 @@ package io.element.android.features.preferences.impl.userstatus
|
|||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.offset
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.sizeIn
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.text.input.InputTransformation
|
import androidx.compose.foundation.text.input.InputTransformation
|
||||||
@@ -34,11 +36,11 @@ import androidx.compose.ui.draw.clip
|
|||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.layout.Layout
|
import androidx.compose.ui.layout.Layout
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.Constraints
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||||
@@ -140,12 +142,17 @@ private fun CurrentStatusRow(
|
|||||||
}
|
}
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text(text = text, modifier = Modifier.padding(vertical = 16.dp)) },
|
headlineContent = { Text(text = text, modifier = Modifier.padding(vertical = 16.dp)) },
|
||||||
leadingContent = ListItemContent.Custom({
|
leadingContent = ListItemContent.Custom { EmojiText(emoji) },
|
||||||
Text(text = emoji, modifier = Modifier.size(24.dp), textAlign = TextAlign.Center)
|
|
||||||
}),
|
|
||||||
trailingContent = ListItemContent.Custom({
|
trailingContent = ListItemContent.Custom({
|
||||||
IconButton(onClick = onClear) {
|
IconButton(
|
||||||
Icon(imageVector = CompoundIcons.Close(), contentDescription = null)
|
onClick = onClear,
|
||||||
|
// Remove the extra padding caused by IconButton
|
||||||
|
modifier = Modifier.offset(x = 12.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = CompoundIcons.Close(),
|
||||||
|
contentDescription = stringResource(CommonStrings.action_clear),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
@@ -153,6 +160,18 @@ private fun CurrentStatusRow(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun EmojiText(emoji: String) {
|
||||||
|
// Ensure the emoji doesn't scale with fontSize to match icons size
|
||||||
|
val fontSize = with(LocalDensity.current) { 16.dp.toSp() }
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.sizeIn(minWidth = 24.dp, minHeight = 24.dp),
|
||||||
|
text = emoji,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun UserStatusPickerBottomSheet(
|
private fun UserStatusPickerBottomSheet(
|
||||||
@@ -176,15 +195,9 @@ private fun UserStatusPickerBottomSheet(
|
|||||||
val isSelected = currentRawStatus == predefinedUserStatus
|
val isSelected = currentRawStatus == predefinedUserStatus
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text(text = label) },
|
headlineContent = { Text(text = label) },
|
||||||
leadingContent = ListItemContent.Text(text = predefined.emoji),
|
leadingContent = ListItemContent.Custom { EmojiText(predefined.emoji) },
|
||||||
trailingContent = if (isSelected) {
|
trailingContent = if (isSelected) {
|
||||||
ListItemContent.Custom({
|
ListItemContent.Icon(IconSource.Vector(CompoundIcons.Check()), tintColor = ElementTheme.colors.iconAccentPrimary)
|
||||||
Icon(
|
|
||||||
imageVector = CompoundIcons.Check(),
|
|
||||||
contentDescription = null,
|
|
||||||
tint = ElementTheme.colors.iconAccentPrimary,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
},
|
},
|
||||||
@@ -199,7 +212,7 @@ private fun UserStatusPickerBottomSheet(
|
|||||||
headlineContent = {
|
headlineContent = {
|
||||||
Text(text = stringResource(R.string.common_user_status_custom))
|
Text(text = stringResource(R.string.common_user_status_custom))
|
||||||
},
|
},
|
||||||
leadingContent = ListItemContent.Text(text = "✏️"),
|
leadingContent = ListItemContent.Custom { EmojiText("✏️") },
|
||||||
onClick = {
|
onClick = {
|
||||||
sheetState.hide(coroutineScope) {
|
sheetState.hide(coroutineScope) {
|
||||||
onSelectCustomStatus()
|
onSelectCustomStatus()
|
||||||
@@ -258,22 +271,22 @@ private fun CustomStatusInputRow(
|
|||||||
},
|
},
|
||||||
trailingContent = ListItemContent.Custom({
|
trailingContent = ListItemContent.Custom({
|
||||||
// Layout measures both buttons to determine the max natural width,
|
// Layout measures both buttons to determine the max natural width,
|
||||||
// then places only the active one — no hardcoded padding values needed.
|
// then places only the active one.
|
||||||
Layout(
|
Layout(
|
||||||
content = {
|
content = {
|
||||||
TextButton(onClick = onConfirm, text = saveLabel)
|
TextButton(onClick = onConfirm, text = saveLabel)
|
||||||
TextButton(onClick = onCancel, text = cancelLabel)
|
TextButton(onClick = onCancel, text = cancelLabel)
|
||||||
}
|
}
|
||||||
) { measurables, constraints ->
|
) { measurables, constraints ->
|
||||||
val placeables = measurables.map { it.measure(Constraints()) }
|
val placeables = measurables.map { it.measure(constraints) }
|
||||||
val maxWidth = placeables.maxOf { it.width }
|
val maxWidth = placeables.maxOf { it.width }
|
||||||
val maxHeight = placeables.maxOf { it.height }
|
val maxHeight = placeables.maxOf { it.height }
|
||||||
layout(maxWidth, maxHeight) {
|
layout(maxWidth, maxHeight) {
|
||||||
if (hasChanges) {
|
val active = if (hasChanges) placeables[0] else placeables[1]
|
||||||
placeables[0].placeRelative(0, 0)
|
active.placeRelative(
|
||||||
} else {
|
x = (maxWidth - active.width) / 2,
|
||||||
placeables[1].placeRelative(0, 0)
|
y = (maxHeight - active.height) / 2,
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -287,7 +300,7 @@ private fun CustomStatusInputRow(
|
|||||||
.clickable { },
|
.clickable { },
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
Text(text = emoji, style = ElementTheme.typography.fontBodyLgRegular)
|
EmojiText(emoji)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user