I like to change the background color of a link when being tapped and reset it when the finger is lifted.
Here is a library which makes this possible for the former view system: https://github.com/saket/Better-Link-Movement-Method
Is that possible with
ClickableText#style
?
Copy code
ClickableText(
text = annotatedString,
style = TextStyle(
background = tapColor // <-- only change on tap
),
onClick = {
annotatedString
.getStringAnnotations(tag = tag, start = it, end = it)
.firstOrNull()
?.let { range -> onClick(range.item) }
}
)
ClickableText is going to be deprecated in 1.7, we have proper link support now. cc @Anastasia [G]
t
Tobias Preuss
04/10/2024, 5:11 AM
@Zach Klippenstein (he/him) [MOD] Which composable do you recommend instead?
a
Anastasia [G]
04/10/2024, 11:48 AM
The new API doesn't support the pressed state (yet), only hovered and focused. This is mostly because we didn't have a signal that pressed is needed right away. Though I've just made the changes and sent it for review.
So for the new API you don't need a special composable, you just use the
Text
. The key is to add the
LinkAnnotation
to your annotated string.
👍 1
t
Tobias Preuss
04/10/2024, 7:00 PM
Thanks. I guess this will be released with a future version of compose-bom then?! What is the current state of the art to do what I described?