@@ -2,7 +2,7 @@ package com.nononsenseapps.feeder.ui.compose.text
2
2
3
3
import android.content.res.Resources
4
4
import android.text.Annotation
5
- import android.text.SpannedString
5
+ import android.text.Spanned
6
6
import androidx.annotation.StringRes
7
7
import androidx.compose.runtime.Composable
8
8
import androidx.compose.runtime.ReadOnlyComposable
@@ -24,20 +24,22 @@ fun resources(): Resources {
24
24
@Composable
25
25
fun annotatedStringResource (@StringRes id : Int ): AnnotatedString {
26
26
val resources = resources()
27
- val text = resources.getText(id) as SpannedString
27
+ val text = resources.getText(id)
28
28
29
29
return buildAnnotatedString {
30
30
this .append(text.toString())
31
31
32
- for (annotation in text.getSpans<Annotation >()) {
33
- when (annotation.key) {
34
- " style" -> {
35
- getSpanStyle(annotation.value)?.let { spanStyle ->
36
- addStyle(
37
- spanStyle,
38
- text.getSpanStart(annotation),
39
- text.getSpanEnd(annotation),
40
- )
32
+ if (text is Spanned ) {
33
+ for (annotation in text.getSpans<Annotation >()) {
34
+ when (annotation.key) {
35
+ " style" -> {
36
+ getSpanStyle(annotation.value)?.let { spanStyle ->
37
+ addStyle(
38
+ spanStyle,
39
+ text.getSpanStart(annotation),
40
+ text.getSpanEnd(annotation),
41
+ )
42
+ }
41
43
}
42
44
}
43
45
}
0 commit comments