mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-01 20:08:57 +00:00
ui: chat tag fixes (#5427)
* ui: chat tag fixes * fix switching tags * change * android: fix switching profile * change * sp * change --------- Co-authored-by: Avently <7953703+avently@users.noreply.github.com>
This commit is contained in:
+35
-20
@@ -5,13 +5,19 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import chat.simplex.common.ui.theme.CurrentColors
|
||||
import chat.simplex.common.ui.theme.DEFAULT_PADDING
|
||||
import androidx.compose.ui.unit.sp
|
||||
import chat.simplex.common.ui.theme.*
|
||||
import chat.simplex.common.ui.theme.ThemeManager.colorFromReadableHex
|
||||
import chat.simplex.common.views.chat.item.isHeartEmoji
|
||||
import chat.simplex.common.views.chat.item.isShortEmoji
|
||||
import chat.simplex.common.views.helpers.toDp
|
||||
import chat.simplex.res.MR
|
||||
import dev.icerock.moko.resources.compose.painterResource
|
||||
|
||||
@@ -27,31 +33,40 @@ actual fun ChatTagInput(name: MutableState<String>, showError: State<Boolean>, e
|
||||
private fun SingleEmojiInput(
|
||||
emoji: MutableState<String?>
|
||||
) {
|
||||
val state = remember { mutableStateOf(TextFieldValue(emoji.value ?: "")) }
|
||||
val colors = TextFieldDefaults.textFieldColors(
|
||||
textColor = if (isHeartEmoji(emoji.value ?: "")) Color(0xffD63C31) else MaterialTheme.colors.onPrimary,
|
||||
backgroundColor = Color.Unspecified,
|
||||
focusedIndicatorColor = MaterialTheme.colors.secondary.copy(alpha = 0.6f),
|
||||
unfocusedIndicatorColor = CurrentColors.value.colors.secondary.copy(alpha = 0.3f),
|
||||
cursorColor = MaterialTheme.colors.secondary,
|
||||
)
|
||||
TextField(
|
||||
value = emoji.value?.let { TextFieldValue(it) } ?: TextFieldValue(""),
|
||||
value = state.value,
|
||||
onValueChange = { newValue ->
|
||||
if (newValue.text == emoji.value) return@TextField
|
||||
if (newValue.text == emoji.value) {
|
||||
state.value = newValue
|
||||
return@TextField
|
||||
}
|
||||
val newValueClamped = newValue.text.replace(emoji.value ?: "", "")
|
||||
emoji.value = if (isShortEmoji(newValueClamped)) newValueClamped else null
|
||||
val isEmoji = isShortEmoji(newValueClamped)
|
||||
emoji.value = if (isEmoji) newValueClamped else null
|
||||
state.value = if (isEmoji) newValue else TextFieldValue()
|
||||
},
|
||||
singleLine = true,
|
||||
maxLines = 1,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.padding(4.dp),
|
||||
.padding(4.dp)
|
||||
.size(width = TextFieldDefaults.MinHeight.value.sp.toDp(), height = TextFieldDefaults.MinHeight),
|
||||
textStyle = LocalTextStyle.current.copy(fontFamily = EmojiFont, textAlign = TextAlign.Center),
|
||||
placeholder = {
|
||||
Icon(
|
||||
painter = painterResource(MR.images.ic_add_reaction),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colors.secondary
|
||||
)
|
||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Icon(
|
||||
painter = painterResource(MR.images.ic_add_reaction),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colors.secondary
|
||||
)
|
||||
}
|
||||
},
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
backgroundColor = Color.Unspecified,
|
||||
focusedIndicatorColor = MaterialTheme.colors.secondary.copy(alpha = 0.6f),
|
||||
unfocusedIndicatorColor = CurrentColors.value.colors.secondary.copy(alpha = 0.3f),
|
||||
cursorColor = MaterialTheme.colors.secondary,
|
||||
),
|
||||
colors = colors,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user