jeziellago / compose-markdown

Markdown Text for Android Jetpack Compose 📋.
MIT License
567 stars 47 forks source link

pointerInput not working in MarkdownText #85

Closed devpawann closed 2 months ago

devpawann commented 7 months ago
 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.

Corrob commented 6 months ago

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.

devpawann commented 6 months ago

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

HXavier21 commented 3 months ago

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.