feat: Add custom accessibility annotations to AnnotatedStringResource - #1402
feat: Add custom accessibility annotations to AnnotatedStringResource#1402francoisadam wants to merge 3 commits into
Conversation
| annotatedString = annotatedString.buildWithAccessibilitySpan(it, start, end) | ||
| } | ||
| append(annotatedString) | ||
| getSpans(0, length, Any::class.java).forEach { | ||
| val start = getSpanStart(it) | ||
| val end = getSpanEnd(it) | ||
| buildWithSpanStyle(it, start, end, density, colors, typography) |
There was a problem hiding this comment.
I'm not sure to fully understand why we duplicated this part of the code. Can't we merge the tts handling with the already existing buildWithSpan which is already parsing the entire string/annotations once?
There was a problem hiding this comment.
That's the frustrating part, TtsSpan in spannable uses metadata to add info for Tts to better read the words but this is not possible yet in compose and AnnotatedStrings (well only Verbatim is possible for now)
So the only way I found was to actually reformat the string itself to make it more readable by Tts.
The first part with buildWithAccessibilitySpan updates the strings before using append, and the second part with buildWithSpanStyle only adds styling to the annotated string (and so needs to be done after the append)
But if you know how to extend the TtsAnnotation from Compose, or a better way to do this I'm all ears 🙏
📋 Changes
🤔 Context
For most content descriptions, TalkBack won't read properly the words unless we do some formatting.
Before Compose, there was the option to use TtsSpan to add metadate to text and help TalkBack properly read the words.
But there is only one annotation available for Compose as of right now (Verbatim), so we need to do it manually for now.
✅ Checklist
📸 Screenshots