Skip to content

Commit

Permalink
fix: HtmlText should only add pointerInput Modifier with url tags exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4rl3x committed Sep 19, 2022
1 parent 3545bae commit b59e52e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion html-text/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply from: '../buildCompose.gradle'

ext {
PUBLISH_GROUP_ID = 'de.charlex.compose'
PUBLISH_VERSION = '1.3.0'
PUBLISH_VERSION = '1.3.1'
PUBLISH_ARTIFACT_ID = 'html-text'
}

Expand Down
11 changes: 7 additions & 4 deletions html-text/src/main/java/de/charlex/compose/HtmlText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ fun HtmlText(
) {
val context = LocalContext.current
val annotatedString = context.resources.getText(textId).toAnnotatedString(urlSpanStyle, colorMapping)
val clickable = annotatedString.getStringAnnotations(0, annotatedString.length-1).any { it.tag == "url" }

val uriHandler = LocalUriHandler.current
val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }

Text(
modifier = modifier.pointerInput(Unit) {
modifier = modifier.then(if(clickable) Modifier.pointerInput(Unit) {
detectTapGestures(onTap = { pos ->
layoutResult.value?.let { layoutResult ->
val position = layoutResult.getOffsetForPosition(pos)
Expand All @@ -94,7 +95,7 @@ fun HtmlText(
}
}
})
},
} else Modifier),
text = annotatedString,
color = color,
fontSize = fontSize,
Expand Down Expand Up @@ -164,11 +165,13 @@ fun HtmlText(
Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
}.toAnnotatedString(urlSpanStyle, colorMapping)

val clickable = annotatedString.getStringAnnotations(0, annotatedString.length-1).any { it.tag == "url" }

val uriHandler = LocalUriHandler.current
val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }

Text(
modifier = modifier.pointerInput(Unit) {
modifier = modifier.then(if(clickable) Modifier.pointerInput(Unit) {
detectTapGestures(onTap = { pos ->
layoutResult.value?.let { layoutResult ->
val position = layoutResult.getOffsetForPosition(pos)
Expand All @@ -181,7 +184,7 @@ fun HtmlText(
}
}
})
},
} else Modifier),
text = annotatedString,
color = color,
fontSize = fontSize,
Expand Down

0 comments on commit b59e52e

Please sign in to comment.