Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface URI Click Callbacks for HTML Links #471

Closed
Kkotiswar opened this issue Dec 23, 2024 · 3 comments
Closed

Surface URI Click Callbacks for HTML Links #471

Kkotiswar opened this issue Dec 23, 2024 · 3 comments

Comments

@Kkotiswar
Copy link

Title: Surface URI Click Callbacks for HTML Links

Problem:

  • RichText currently opens HTML links directly in the browser.
  • No callback for intercepting link clicks for tracking or custom behavior.

Requirement:

  • Introduce onUriClick callback to RichText.
  • Callback should pass the clicked URL string.
  • Default behavior (open in browser) if onUriClick is not provided.
  • Callback returns Boolean which decides whether to open URI or not.

Benefits:

  • Enable tracking link clicks.
  • Allow custom navigation logic.
  • Maintain default behavior.
  • Increased flexibility for developer.
  • Backward compatible

Code Location:

  • Modify BasicRichText or RichText where detectTapGestures handles link clicks.
@MohamedRejeb
Copy link
Owner

Thanks for opening this issue. Actually, it's possible to intercept Uri clicks, it's not straightforward though.

It's listed in the documentation: https://mohamedrejeb.github.io/compose-rich-editor/links/#add-links

val myUriHandler = remember {
    object : UriHandler {
        override fun openUri(uri: String) {
            // Link clicked
        }
    }
}

CompositionLocalProvider(
    LocalUriHandler provides myUriHandler,
) {
    RichText()
}

@Kkotiswar
Copy link
Author

Kkotiswar commented Dec 27, 2024

@MohamedRejeb thanks for the info, I saw one more issue, where this library is not able to render the text that is currently in between html tags
i.e <html> some text </html> displays nothing

@MohamedRejeb
Copy link
Owner

Currently, I'm skipping anything outside <body> tag. I've created a new issue for that #479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants