4

I have a text with a link in clickable card. I followed this solution to open the link from the text.

 val htmlText = description.parseHtml()
    OutlinedCard(
        onClick = {}
    ) {
        ClickableText(
            text = htmlText,
            onClick = { offset ->
                htmlText.getStringAnnotations(
                    tag = "policy",
                    start = offset,
                    end = offset
                ).firstOrNull()?.let { stringAnnotation ->
                    uriHandler.openUri(stringAnnotation.item)
                }
            })
    }

The link is working fine when I click on it. The problem is that all the text (which fills the card) is now clickable, so the card does not detect gesture anymore.

What I want is that only the portion of the text corresponding to the link be clickable, not all the text.

In the implementation of ClickableText, this modifier is added :

 val pressIndicator = Modifier.pointerInput(onClick) {
        detectTapGestures { pos ->
            layoutResult.value?.let { layoutResult ->
                onClick(layoutResult.getOffsetForPosition(pos))
            }
        }
    }

I don't know if I can modify it to support what I need or if I need a different solution.

I think this is a pretty common case, and it worked fine in xml with LinkMovementMethod.

Benjamin Ledet
  • 942
  • 1
  • 9
  • 19
  • While I have not found a concrete solution, I have found a workaround where you use normal Text and place an invisible clickable box on top. This is also the only solution that works for screen readers right now: https://stackoverflow.com/a/71518952/14375655 – Tobias Apr 14 '22 at 23:16

0 Answers0