Cropping long reactions to two chars for emojis

This commit is contained in:
Vitor Pamplona
2023-06-14 20:27:46 -04:00
parent a44703cb49
commit 9a7a94cb77
3 changed files with 12 additions and 6 deletions
@@ -178,6 +178,12 @@ fun RenderLikeGallery(
likeEvents.isNotEmpty()
}
val shortReaction by remember {
derivedStateOf {
reactionType.take(2)
}
}
if (isNotEmpty) {
Row(remember { Modifier.fillMaxWidth() }) {
Box(
@@ -192,7 +198,7 @@ fun RenderLikeGallery(
.align(Alignment.TopEnd)
}
when (reactionType) {
when (shortReaction) {
"+" -> Icon(
painter = painterResource(R.drawable.ic_liked),
null,
@@ -200,7 +206,7 @@ fun RenderLikeGallery(
tint = Color.Unspecified
)
"-" -> Text(text = "\uD83D\uDC4E", modifier = modifier)
else -> Text(text = reactionType, modifier = modifier)
else -> Text(text = shortReaction, modifier = modifier)
}
}
@@ -504,14 +504,14 @@ fun LikeIcon(baseNote: Note, iconSize: Dp = 20.dp, grayTint: Color, loggedIn: Us
val reactionsState by baseNote.live().reactions.observeAsState()
var reactionType by remember(baseNote) {
mutableStateOf<String?>(null)
mutableStateOf<String>("+")
}
LaunchedEffect(key1 = reactionsState) {
launch(Dispatchers.Default) {
val newReactionType = reactionsState?.note?.isReactedBy(loggedIn)
if (reactionType != newReactionType) {
reactionType = newReactionType
reactionType = newReactionType?.take(2) ?: "+"
}
}
}
@@ -531,7 +531,7 @@ fun LikeIcon(baseNote: Note, iconSize: Dp = 20.dp, grayTint: Color, loggedIn: Us
)
}
"-" -> Text(text = "\uD83D\uDC4E")
else -> Text(text = reactionType!!)
else -> Text(text = reactionType)
}
} else {
Icon(
@@ -64,7 +64,7 @@ class UpdateReactionTypeViewModel(val account: Account) : ViewModel() {
}
fun addChoice() {
val newValue = nextChoice.text.trim()
val newValue = nextChoice.text.trim().take(2)
reactionSet = reactionSet + newValue
nextChoice = TextFieldValue("")