jeziellago/compose-markdown

pointerInput not working in MarkdownText

Closed this issue · 3 comments

 MarkdownText(
            markdown = message,
            modifier = Modifier.pointerInput(Unit) {
                detectTapGestures(
                    onLongPress = {
                        Log.d("TAG", "long pressed")
                    }
                )
            }
        )

This doesn't work, if I use normal text the above code works perfectly.

I also have issues with the following:

Box(Modifier.clickable { println("clicked ") }) {
  MarkdownText("Click Here")
}

It seems it works if you tap just above the text but not directly on it :/ It works perfectly fine if you change it to just Text.

I also have issues with the following:

Box(Modifier.clickable { println("clicked ") }) {
  MarkdownText("Click Here")
}

It seems it works if you tap just above the text but not directly on it :/ It works perfectly fine if you change it to just Text.

So wrapping it with box worked?

I made the change below to solve it for me.
https://github.com/devpawann/compose-markdown/tree/add-long-click-handler

There are several lines of comments that says:

// In MarkdownText()
// this option will disable all clicks on links, inside the markdown text
// it also enable the parent view to receive the click event
disableLinkMovementMethod: Boolean = false

So you can just pass a parameter to solve the problem:

MarkdownText(
    markdown = """
    # Markdown Text
    This is a simple markdown text.
    ---
    """.trimIndent(),
    disableLinkMovementMethod = true,
    modifier = Modifier.pointerInput(Unit) {
        detectTapGestures(onLongPress = {
            Toast.makeText(
                context, "On long press", Toast.LENGTH_SHORT
            ).show()
        })
    }
)

However, which will disable all clicks on links, inside the markdown text, so I am trying to find a good way to accommodate such issues.