Skip to content

Commit

Permalink
add annotationProvider to demo and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin-LL committed Mar 8, 2024
1 parent 8c07a5d commit 0ea7a37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -126,7 +131,8 @@ AutoLinkText(
),
onClick = {
println("Hashtag ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.hashtag" },
),
TextRule(
textMatcher = TextMatcher.RegexMatcher(Regex("@\\w+")),
Expand All @@ -136,7 +142,8 @@ AutoLinkText(
),
onClick = {
println("Mention ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.mentions" },
)
)
)
Expand Down Expand Up @@ -171,7 +178,8 @@ AutoLinkText(
},
onClick = {
println("Hashtag ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.hashtag" },
),
)
)
Expand All @@ -191,6 +199,7 @@ AutoLinkText(
TextRule(
textMatcher = TextMatcher.StringMatcher("important"),
style = SpanStyle(color = Color.Red),
annotationProvider = { null },
),
)
)
Expand Down Expand Up @@ -226,6 +235,7 @@ AutoLinkText(
matches.filterIndexed { index, _ -> index % 2 == 0 }
},
style = SpanStyle(color = Color.Blue),
annotationProvider = { null },
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ fun MainScreen() {
),
onClick = {
println("Hashtag ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.hashtag" },
),
TextRule(
textMatcher = TextMatcher.RegexMatcher(Regex("@\\w+")),
Expand All @@ -127,7 +128,8 @@ fun MainScreen() {
),
onClick = {
println("Mention ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.mentions" },
)
)
)
Expand Down Expand Up @@ -156,7 +158,8 @@ fun MainScreen() {
},
onClick = {
println("Hashtag ${it.matchedText} clicked")
}
},
annotationProvider = { "https://link.to.hashtag" },
),
)
)
Expand All @@ -170,6 +173,7 @@ fun MainScreen() {
TextRule(
textMatcher = TextMatcher.StringMatcher("important"),
style = SpanStyle(color = Color.Red),
annotationProvider = { null },
),
)
)
Expand Down Expand Up @@ -199,6 +203,7 @@ fun MainScreen() {
matches.filterIndexed { index, _ -> index % 2 == 0 }
},
style = SpanStyle(color = Color.Blue),
annotationProvider = { null },
),
)
)
Expand All @@ -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 },
)
)
)
Expand Down

0 comments on commit 0ea7a37

Please sign in to comment.