Is it possible to programmatically determine wheth...
# compose
l
Is it possible to programmatically determine whether or not a composable is being focused for talkback announcement? And then to intercept the “next” gesture that would move the focus to the next composable.
a
Apply
Modifier.clearAndSetSemantics {}
on the element that you don't want TalkBack to announce.
l
Ya well the issue is more complex than that. I want it announced.
a
If an element has semantics and you aren't clearing it manually, it will be announced.
l
I agree with that. My issue is quite complicated. The item is an expandable list. When the user gets to the bottom to the last item that is visible in the “collapsed” version, I want the “next” action to expand the list rather than scroll it.
z
Compose 1.5 (still in beta) introduces a
traversalIndex
field in the
Modifier.semantics
block. Maybe you can add some conditional logic to that modifier that will alter the focus order based on the index of the item in the list & the collapsed state. not sure how you’ll trigger the expand though
Maybe you can combine it with the
onFocusChanged
(if that triggers when talkback changes focus, I’m not sure)
l
I am deep in that beta haha. The traversal happens correctly I just want the expansion and there are no callbacks that I have found that work…
onFocusChanged
is only updated when you focus on a component like a text entry, and not when it is focused for talkback but when it is focused for typing.
I have a work around but it is quite indirect.
It would be nice if we could tell if talkback was enabled…
or to know what is being focused…
z
there is a way to tell if talkback is enabled:
Copy code
fun Context.getEnabledAccessibilityServices(): List<AccessibilityServiceInfo> {
  val accessibilityManager: AccessibilityManager =
    getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
  return accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
}
l
Right ya, thank you!
u
Hi @Lucas Kivi, do you mind sharing the workaround to detect if a composable is being focused by the talkback?
l
It is impossible.. for my solution I did some crap with listening to the
LazyListState
. You can upvote this post if you so desire. https://stackoverflow.com/q/76461364/12385518
🙏 1
u
I upvoted but I don't think it's gonna +1 because my new profile doesn't have enough reputation on StackOverflow. I filed these two ticket in Google Compose team's bug tracker. I'd appreciate if you could vote. If those tickets have enough votes, they might consider it. https://issuetracker.google.com/u/1/issues/305580465 https://issuetracker.google.com/u/1/issues/252992211
1