Skip to content

Commit

Permalink
[Jetcaster] Refactor to use fromHtml in AnnotatedString (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
bentrengrove authored Sep 10, 2024
2 parents bf6dead + f59364f commit 49f1048
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,19 @@ import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.buildAnnotatedString
import androidx.core.text.HtmlCompat
import androidx.compose.ui.text.fromHtml

/**
* A container for text that should be HTML formatted. This container will handle building the
* annotated string from [text], and enable text selection if [text] has any selectable element.
*
* TODO: Remove/update once the project is using Compose 1.7 as that version provides improved
* support for HTML formatting.
* See: https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0-alpha07
*/
@Composable
fun HtmlTextContainer(
text: String,
content: @Composable (AnnotatedString) -> Unit
) {
val annotatedString = remember(key1 = text) {
buildAnnotatedString {
val htmlCompat = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_COMPACT)
append(htmlCompat)
}
AnnotatedString.fromHtml(htmlString = text)
}
SelectionContainer {
content(annotatedString)
Expand Down

0 comments on commit 49f1048

Please sign in to comment.