How do I make the accessibility service announce c...
# compose
a
How do I make the accessibility service announce custom states? I am building an accordion and I can't get the VoiceOver on my mac to say 'expanded' or 'collapsed' when the heading is focused. I tried stateDescription, which is probably not what I want (docs say it's a dev thing), but can't figure this out:
Copy code
Modifier
    .semantics {
        stateDescription = if (state.expanded) "expanded" else "collapsed"
    }
👀 1
also tried setting collapse/expand{} actions. doesn't announce it. I might be missing some sort of modifier for this job. Like togglable() or maybe some role
Progress (sort of). I am using the collapse/expanded actions and switched to Android (Talkback). When i touch the header it does say that it is collapsed. But now I cannot figure out how to say 'expanded' when i expand the section.
Copy code
Button(
        modifier = modifier.semantics {
            expand {
                state.expanded = true
                true
            }
            collapse {
                state.expanded = false
                true
            }
        },
Ok figured it out. Need to add either expand OR collapse. Works correctly now:
Copy code
Button(
        modifier = modifier.semantics {
            if (state.expanded) {
                collapse {
                    state.expanded = false
                    true
                }
            } else {
                expand {
                    state.expanded = true
                    true
                }
            }
        },
This does work on Android, but doesnt work on JVM (Mac), which I believe is a bug. Opened an issue at https://youtrack.jetbrains.com/issue/CMP-7995/VoiceOver-does-not-read-out-loud-the-state-of-collapse-expanded-semantic