Does anyone have a Text-like component, that is ca...
# compose-desktop
o
Does anyone have a Text-like component, that is capable of handling links (urls) inside? I have
AnnotatedString
with some url annotations, and I’m struggling to make it working properly with hover interactions. I want (like in a browser) to highlight links when they are hovered, and change pointer icon to hand. It causes infinite recomposition because when I handle enter/move pointer event, the
AnnotatedString
is changed (to highlight hovered part of the text with url), which causes recomposition of
BasicText
, and then
onTextLayout
yields different
TextLayoutResult
(because input changed, particularly span styles), which causes remembered mutable state to be modified, which triggers more changes and causes recomposition again, ad infinum. Also, it seems recomposition causes synthentic
PointerEventType.Exit
to be sent, which causes un-hover path to be triggered. I just can’t find how to get it all together. Any ideas, maybe?
a
This seems to work for me:
Ah, I’m highlighting on the wrong event
Changing the remembered
TextLayoutResult
here doesn’t cause recomposition, because it’s only read in
onPointerEvent
.
o
@Alexander Maryanovsky I’m doing pretty much the same, but maybe I’ve did something wrong. I’ll try your variant when I get back to that code. Thanks!
Your variant is working. The only difference (that was significant) is this: My modifier:
Copy code
.then(if (hoverRange != null) Modifier.pointerHoverIcon(PointerIconDefaults.Hand, overrideDescendants = true) else Modifier)
Your modifier:
Copy code
.pointerHoverIcon(if (hoverRange != null) PointerIconDefaults.Hand else PointerIconDefaults.Default, overrideDescendants = true)
I was using no modifier in case of not hovered because text may or may not be wrapped into SelectionContainer, and thus no-hover cursor would be different… Now I wonder why is that.
Duh, in
SelectionContainer
click is not working, because it is probably intercepted by selection handling code
a
Glad I could help, if it did help 😀