Fixes text's vertical alignment when emoji's are present.

This commit is contained in:
Vitor Pamplona
2024-02-20 12:28:46 -05:00
parent 0d44c44c6e
commit ae291d278f
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.ui.components
import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.InlineTextContent import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material3.LocalContentColor import androidx.compose.material3.LocalContentColor
@@ -566,24 +565,29 @@ fun CreateClickableTextWithEmoji(
if (emojiLists == null) { if (emojiLists == null) {
CreateClickableText(clickablePart, suffix, maxLines, overrideColor, fontWeight, route, nav) CreateClickableText(clickablePart, suffix, maxLines, overrideColor, fontWeight, route, nav)
} else { } else {
val clickablePartStyle =
SpanStyle(
color = overrideColor ?: MaterialTheme.colorScheme.primary,
fontWeight = fontWeight,
)
val nonClickablePartStyle =
SpanStyle(
color = overrideColor ?: MaterialTheme.colorScheme.onBackground,
fontWeight = fontWeight,
)
ClickableInLineIconRenderer( ClickableInLineIconRenderer(
emojiLists!!.part1, emojiLists!!.part1,
maxLines, maxLines,
LocalTextStyle.current clickablePartStyle,
.copy(color = overrideColor ?: MaterialTheme.colorScheme.primary, fontWeight = fontWeight)
.toSpanStyle(),
) { ) {
nav(route) nav(route)
} }
InLineIconRenderer( InLineIconRenderer(
emojiLists!!.part2, emojiLists!!.part2,
LocalTextStyle.current nonClickablePartStyle,
.copy(
color = overrideColor ?: MaterialTheme.colorScheme.onBackground,
fontWeight = fontWeight,
)
.toSpanStyle(),
maxLines = maxLines, maxLines = maxLines,
) )
} }
@@ -677,7 +681,7 @@ fun ClickableInLineIconRenderer(
} }
} }
BasicText( Text(
text = annotatedText, text = annotatedText,
modifier = pressIndicator, modifier = pressIndicator,
inlineContent = inlineContent, inlineContent = inlineContent,