Skip to content

Commit df2b7d2

Browse files
authored
Fixed span styles for URL annotations (#598)
* Fixed span styles Signed-off-by: Arnau Mora Gras <[email protected]> * Pushing initial style to builder Signed-off-by: Arnau Mora Gras <[email protected]> --------- Signed-off-by: Arnau Mora Gras <[email protected]>
1 parent 4c1d9d2 commit df2b7d2

File tree

1 file changed

+6
-3
lines changed
  • app/src/main/kotlin/at/bitfire/davdroid/ui

1 file changed

+6
-3
lines changed

app/src/main/kotlin/at/bitfire/davdroid/ui/UiUtils.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.widget.Toast
2121
import androidx.annotation.DrawableRes
2222
import androidx.appcompat.app.AppCompatDelegate
2323
import androidx.browser.customtabs.CustomTabsClient
24+
import androidx.compose.material.LocalTextStyle
2425
import androidx.compose.runtime.Composable
2526
import androidx.compose.ui.graphics.asImageBitmap
2627
import androidx.compose.ui.graphics.painter.BitmapPainter
@@ -128,6 +129,8 @@ object UiUtils {
128129
@OptIn(ExperimentalTextApi::class)
129130
@Composable
130131
fun Spanned.toAnnotatedString() = buildAnnotatedString {
132+
val style = LocalTextStyle.current.toSpanStyle()
133+
pushStyle(style)
131134
val spanned = this@toAnnotatedString
132135
append(spanned.toString())
133136
for (span in getSpans<Any>(0, spanned.length)) {
@@ -137,11 +140,11 @@ object UiUtils {
137140
is StyleSpan ->
138141
when (span.style) {
139142
Typeface.BOLD -> addStyle(
140-
SpanStyle(fontWeight = FontWeight.Bold),
143+
style.copy(fontWeight = FontWeight.Bold),
141144
start = start, end = end
142145
)
143146
Typeface.ITALIC -> addStyle(
144-
SpanStyle(fontStyle = FontStyle.Italic),
147+
style.copy(fontStyle = FontStyle.Italic),
145148
start = start, end = end
146149
)
147150
}
@@ -151,7 +154,7 @@ object UiUtils {
151154
start = start, end = end
152155
)
153156
addStyle(
154-
SpanStyle(textDecoration = TextDecoration.Underline),
157+
style.copy(textDecoration = TextDecoration.Underline),
155158
start = start, end = end
156159
)
157160
}

0 commit comments

Comments
 (0)