Slight adjustment on the rendering of hashtags.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.components
|
package com.vitorpamplona.amethyst.ui.components
|
||||||
|
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.animation.Crossfade
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
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.FlowRow
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.text.BasicText
|
import androidx.compose.foundation.text.BasicText
|
||||||
import androidx.compose.foundation.text.ClickableText
|
|
||||||
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.Icon
|
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.res.painterResource
|
||||||
import androidx.compose.ui.text.Placeholder
|
import androidx.compose.ui.text.Placeholder
|
||||||
import androidx.compose.ui.text.PlaceholderVerticalAlign
|
import androidx.compose.ui.text.PlaceholderVerticalAlign
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.withStyle
|
import androidx.compose.ui.text.withStyle
|
||||||
@@ -318,10 +319,8 @@ private fun NoProtocolUrlRenderer(word: SchemelessUrlSegment) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RenderUrl(segment: SchemelessUrlSegment) {
|
private fun RenderUrl(segment: SchemelessUrlSegment) {
|
||||||
Row() {
|
ClickableUrl(segment.url, "https://${segment.url}")
|
||||||
ClickableUrl(segment.url, "https://${segment.url}")
|
segment.extras?.let { it1 -> Text(it1) }
|
||||||
segment.extras?.let { it1 -> Text(it1) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -545,9 +544,7 @@ private fun DisplayFullNote(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HashTag(word: HashTagSegment, nav: (String) -> Unit) {
|
fun HashTag(word: HashTagSegment, nav: (String) -> Unit) {
|
||||||
Row() {
|
RenderHashtag(word, nav)
|
||||||
RenderHashtag(word, nav)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -556,39 +553,51 @@ private fun RenderHashtag(
|
|||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val primary = MaterialTheme.colorScheme.primary
|
val primary = MaterialTheme.colorScheme.primary
|
||||||
val hashtagIcon = remember(segment.hashtag) { checkForHashtagWithIcon(segment.hashtag, primary) }
|
val hashtagIcon = remember(segment.hashtag) {
|
||||||
ClickableText(
|
checkForHashtagWithIcon(segment.hashtag, primary)
|
||||||
text = buildAnnotatedString {
|
}
|
||||||
withStyle(
|
|
||||||
LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary).toSpanStyle()
|
|
||||||
) {
|
|
||||||
append("#${segment.hashtag}")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onClick = { nav("Hashtag/${segment.hashtag}") }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (hashtagIcon != null) {
|
val regularText =
|
||||||
val myId = "inlineContent"
|
SpanStyle(color = MaterialTheme.colorScheme.onBackground)
|
||||||
val emptytext = buildAnnotatedString {
|
|
||||||
withStyle(
|
val clickableTextStyle =
|
||||||
LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary).toSpanStyle()
|
SpanStyle(color = primary)
|
||||||
) {
|
|
||||||
append("")
|
val annotatedTermsString = buildAnnotatedString {
|
||||||
appendInlineContent(myId, "[icon]")
|
withStyle(clickableTextStyle) {
|
||||||
|
pushStringAnnotation("routeToHashtag", "")
|
||||||
|
append("#${segment.hashtag}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hashtagIcon != null) {
|
||||||
|
withStyle(clickableTextStyle) {
|
||||||
|
pushStringAnnotation("routeToHashtag", "")
|
||||||
|
appendInlineContent("inlineContent", "[icon]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
segment.extras?.ifBlank { "" }?.let {
|
||||||
|
withStyle(regularText) {
|
||||||
|
append(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Empty Text for Size of Icon
|
|
||||||
Text(
|
|
||||||
text = emptytext,
|
|
||||||
inlineContent = mapOf(
|
|
||||||
myId to InlineIcon(hashtagIcon)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
segment.extras?.ifBlank { "" }?.let {
|
|
||||||
Text(text = 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
|
@Composable
|
||||||
|
|||||||
Reference in New Issue
Block a user