orangy
08/08/2022, 11:39 AMAnnotatedString
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?Alexander Maryanovsky
08/08/2022, 2:53 PMTextLayoutResult
here doesn’t cause recomposition, because it’s only read in onPointerEvent
.orangy
08/09/2022, 6:04 PM.then(if (hoverRange != null) Modifier.pointerHoverIcon(PointerIconDefaults.Hand, overrideDescendants = true) else Modifier)
Your modifier:
.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.SelectionContainer
click is not working, because it is probably intercepted by selection handling codeAlexander Maryanovsky
08/10/2022, 10:25 AM