Use LocalContentColor for ClickableTextWithLink (#725)

This commit is contained in:
Ricki Hirner 2024-04-12 18:02:25 +02:00 committed by GitHub
parent c3b3dd4e35
commit 114084f405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -21,7 +21,6 @@ import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.browser.customtabs.CustomTabsClient
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.asImageBitmap
@ -30,6 +29,7 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.UrlAnnotation
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontStyle
@ -129,10 +129,9 @@ object UiUtils {
@OptIn(ExperimentalTextApi::class)
@Composable
fun Spanned.toAnnotatedString() = buildAnnotatedString {
val style = LocalTextStyle.current.toSpanStyle()
pushStyle(style)
val spanned = this@toAnnotatedString
append(spanned.toString())
for (span in getSpans<Any>(0, spanned.length)) {
val start = getSpanStart(span)
val end = getSpanEnd(span)
@ -140,11 +139,11 @@ object UiUtils {
is StyleSpan ->
when (span.style) {
Typeface.BOLD -> addStyle(
style.copy(fontWeight = FontWeight.Bold),
SpanStyle(fontWeight = FontWeight.Bold),
start = start, end = end
)
Typeface.ITALIC -> addStyle(
style.copy(fontStyle = FontStyle.Italic),
SpanStyle(fontStyle = FontStyle.Italic),
start = start, end = end
)
}
@ -154,7 +153,7 @@ object UiUtils {
start = start, end = end
)
addStyle(
style.copy(
SpanStyle(
textDecoration = TextDecoration.Underline,
color = MaterialTheme.colors.secondary
),

View file

@ -5,6 +5,7 @@
package at.bitfire.davdroid.ui.widget
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
@ -23,7 +24,7 @@ fun ClickableTextWithLink(
ClickableText(
text = text,
style = style,
style = style.copy(color = LocalContentColor.current),
modifier = modifier
) { index ->
// Get the tapped position, and check if there's any link