Slight adjustment on the rendering of hashtags.

This commit is contained in:
Vitor Pamplona
2023-10-23 12:22:42 -04:00
parent 5b0fc7982b
commit 6831349f2f
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.ui.components
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -8,7 +9,6 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material3.Icon
@@ -36,6 +36,7 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
@@ -318,11 +319,9 @@ private fun NoProtocolUrlRenderer(word: SchemelessUrlSegment) {
@Composable
private fun RenderUrl(segment: SchemelessUrlSegment) {
Row() {
ClickableUrl(segment.url, "https://${segment.url}")
segment.extras?.let { it1 -> Text(it1) }
}
}
@Composable
fun RenderCustomEmoji(word: String, state: RichTextViewerState) {
@@ -545,10 +544,8 @@ private fun DisplayFullNote(
@Composable
fun HashTag(word: HashTagSegment, nav: (String) -> Unit) {
Row() {
RenderHashtag(word, nav)
}
}
@Composable
private fun RenderHashtag(
@@ -556,40 +553,52 @@ private fun RenderHashtag(
nav: (String) -> Unit
) {
val primary = MaterialTheme.colorScheme.primary
val hashtagIcon = remember(segment.hashtag) { checkForHashtagWithIcon(segment.hashtag, primary) }
ClickableText(
text = buildAnnotatedString {
withStyle(
LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary).toSpanStyle()
) {
val hashtagIcon = remember(segment.hashtag) {
checkForHashtagWithIcon(segment.hashtag, primary)
}
val regularText =
SpanStyle(color = MaterialTheme.colorScheme.onBackground)
val clickableTextStyle =
SpanStyle(color = primary)
val annotatedTermsString = buildAnnotatedString {
withStyle(clickableTextStyle) {
pushStringAnnotation("routeToHashtag", "")
append("#${segment.hashtag}")
}
},
onClick = { nav("Hashtag/${segment.hashtag}") }
)
if (hashtagIcon != null) {
val myId = "inlineContent"
val emptytext = buildAnnotatedString {
withStyle(
LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary).toSpanStyle()
) {
append("")
appendInlineContent(myId, "[icon]")
withStyle(clickableTextStyle) {
pushStringAnnotation("routeToHashtag", "")
appendInlineContent("inlineContent", "[icon]")
}
}
// Empty Text for Size of Icon
Text(
text = emptytext,
inlineContent = mapOf(
myId to InlineIcon(hashtagIcon)
)
)
}
segment.extras?.ifBlank { "" }?.let {
Text(text = it)
withStyle(regularText) {
append(it)
}
}
}
val inlineContent = if (hashtagIcon != null) {
mapOf("inlineContent" to InlineIcon(hashtagIcon))
} else {
emptyMap()
}
val pressIndicator = Modifier.clickable {
nav("Hashtag/${segment.hashtag}")
}
Text(
text = annotatedTermsString,
modifier = pressIndicator,
inlineContent = inlineContent
)
}
@Composable
private fun InlineIcon(hashtagIcon: HashtagIcon) =