https://kotlinlang.org logo
#compose
Title
# compose
t

Todor Grudev

09/07/2023, 10:16 AM
I have the following component in my app called
HtmlText
the prime responsibility of which is to render a text that has some link in it returned from an API, while this seemed to worked for API < 34, it is not the case for the latter
Copy code
@Composable
fun HtmlText(text: String, modifier: Modifier = Modifier) {
  AndroidView(
    modifier = modifier,
    factory = {
      TextView(it).apply {
        autoLinkMask = Linkify.WEB_URLS
        linksClickable = true
        setLinkTextColor(Color.Blue.toArgb())
      }
    },
    update = {
      it.text = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_COMPACT)
      it.movementMethod = LinkMovementMethod.getInstance()
    }
  )
}
Anyone facing the same problem and how did you solve it?
2 Views