halilozercan / compose-richtext

A collection of Compose libraries for advanced text formatting and alternative display types.
https://halilibo.com/compose-richtext
Apache License 2.0
803 stars 67 forks source link

Clickable links in SelectionContainer are no longer clickable #103

Open sebkur opened 1 year ago

sebkur commented 1 year ago

Here's an example. With the SelectionContainer selecting the text is possible, but clicking the link does nothing. Without it, clicking the link works, but selecting text doesn't work of course:

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
import com.halilibo.richtext.markdown.Markdown
import com.halilibo.richtext.ui.RichText

fun main() {
    singleWindowApplication {
        LazyColumn {
            item {
                Text("Foo")
            }
            item {
                SelectionContainer {
                    RichText(modifier = Modifier.padding(vertical = 8.dp).fillMaxWidth()) {
                        Markdown("[Google](https://www.google.com)", onLinkClicked = { link ->
                            println(link)
                        })
                    }
                }
            }
        }
    }
}

Is there some other way to make text selectable or is this is a bug?

morrisseyai commented 1 year ago

Hi @sebkur, I saw your post on Slack but figured I would answer in both places, to help anyone else who also searches for this issue.

I believe the problem is actually related to this open issue on Compose for Desktop: https://github.com/JetBrains/compose-jb/issues/1450

As a side note: Earlier this year I made some improvements to how we handle clickable text in compose-richtext which solved a common problem developers have with the standard ClickableText component - that is, ClickableText consumes all tap interactions rather than the ones it should be responsible for, which causes a follow-on effect where you lose interaction effects like the ripple on Android, and you lose the ability to allow parent Composables to handle tap events.

☝️ what all this means is that if JetBrains are able to resolve the SelectionContainer issue then having clickable and selectable text in compose-richtext should just work with no changes required by us.

Hope that helps, reach out if you need more info.

sebkur commented 1 year ago

Thanks @morrisseyai