From 0ea7a3796144d5656360dfca1b004038321e9e6e Mon Sep 17 00:00:00 2001 From: Calvin Liang Date: Thu, 7 Mar 2024 19:15:22 -0800 Subject: [PATCH] add annotationProvider to demo and examples --- README.md | 16 +++++++++++++--- .../kotlin/sh/calvin/autolinktext/demo/App.kt | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 372d758..c056a53 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ dependencies { } ``` +### Caveats + +- Google might be deprecating the `ClickableText` API in the future. (See [Google IssueTracker issue 323346994](https://issuetracker.google.com/issues/323346994)) I will try my best to keep this library up to date with the latest Compose APIs. +- Accessibility is not great if your onClick function does something other than opening a link. Hopefully this gets fixed in the future. (See [Google IssueTracker issue 274486643](https://issuetracker.google.com/issues/274486643)) + ### Examples See [demo app code](demoApp/composeApp/src/commonMain/kotlin/sh/calvin/autolinktext/demo/App.kt) for more examples. @@ -126,7 +131,8 @@ AutoLinkText( ), onClick = { println("Hashtag ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.hashtag" }, ), TextRule( textMatcher = TextMatcher.RegexMatcher(Regex("@\\w+")), @@ -136,7 +142,8 @@ AutoLinkText( ), onClick = { println("Mention ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.mentions" }, ) ) ) @@ -171,7 +178,8 @@ AutoLinkText( }, onClick = { println("Hashtag ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.hashtag" }, ), ) ) @@ -191,6 +199,7 @@ AutoLinkText( TextRule( textMatcher = TextMatcher.StringMatcher("important"), style = SpanStyle(color = Color.Red), + annotationProvider = { null }, ), ) ) @@ -226,6 +235,7 @@ AutoLinkText( matches.filterIndexed { index, _ -> index % 2 == 0 } }, style = SpanStyle(color = Color.Blue), + annotationProvider = { null }, ), ) ) diff --git a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/autolinktext/demo/App.kt b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/autolinktext/demo/App.kt index 739fe71..091e717 100644 --- a/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/autolinktext/demo/App.kt +++ b/demoApp/composeApp/src/commonMain/kotlin/sh/calvin/autolinktext/demo/App.kt @@ -117,7 +117,8 @@ fun MainScreen() { ), onClick = { println("Hashtag ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.hashtag" }, ), TextRule( textMatcher = TextMatcher.RegexMatcher(Regex("@\\w+")), @@ -127,7 +128,8 @@ fun MainScreen() { ), onClick = { println("Mention ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.mentions" }, ) ) ) @@ -156,7 +158,8 @@ fun MainScreen() { }, onClick = { println("Hashtag ${it.matchedText} clicked") - } + }, + annotationProvider = { "https://link.to.hashtag" }, ), ) ) @@ -170,6 +173,7 @@ fun MainScreen() { TextRule( textMatcher = TextMatcher.StringMatcher("important"), style = SpanStyle(color = Color.Red), + annotationProvider = { null }, ), ) ) @@ -199,6 +203,7 @@ fun MainScreen() { matches.filterIndexed { index, _ -> index % 2 == 0 } }, style = SpanStyle(color = Color.Blue), + annotationProvider = { null }, ), ) ) @@ -215,7 +220,10 @@ fun MainScreen() { textMatcher = TextMatcher.StringMatcher("this"), onClick = { clickCount++ - } + }, + // as of right now, this is not usable with a screen reader + // due to https://issuetracker.google.com/issues/274486643 + annotationProvider = { null }, ) ) )