You can intercept clicks on the entire composable using onClick or intercept specific markdown link clicks using onLinkClicked.
Note: If you want the parent container to receive tap events instead of the internal link handler, set disableLinkMovementMethod = true.
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp
import dev.jeziellago.compose.markdowntext.MarkdownText
@Composable
fun InteractiveMarkdown() {
val context = LocalContext.current
MarkdownText(
markdown = """
## Interactive content
Visit [GitHub](https://github.com/jeziellago/compose-markdown)
or tap anywhere in this block.
""".trimIndent(),
style = TextStyle(fontSize = 18.sp),
isTextSelectable = true,
onClick = {
Toast.makeText(context, "Block clicked", Toast.LENGTH_SHORT).show()
},
onLinkClicked = {\ url ->
Toast.makeText(context, url, Toast.LENGTH_SHORT).show()
},
)
}
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp
import dev.jeziellago.compose.markdowntext.MarkdownText
@Composable
fun InteractiveMarkdown() {
val context = LocalContext.current
MarkdownText(
markdown = """
## Interactive content
Visit [GitHub](https://github.com/jeziellago/compose-markdown)
or tap anywhere in this block.
""".trimIndent(),
style = TextStyle(fontSize = 18.sp),
isTextSelectable = true,
onClick = {
Toast.makeText(context, "Block clicked", Toast.LENGTH_SHORT).show()
},
onLinkClicked = {
Toast.makeText(context, url, Toast.LENGTH_SHORT).show()
},
)
}