I'm trying to get a voiceover similar to XML:
- First the text is announced
- Then the state of the switch
The expected result is "Sometext on switch" or "Sometext off switch".
In Jetpack Compose it reads "Off sometext off switch" if you double-click it(using talkback to change state) and click again or swipe(to next and back), it reads "On sometext off switch".
Moreover, there is no sounding after double-clicking and changing state to on/off(like XML).
var isChecked by remember { mutableStateOf(false) }
val toggleModifier =
Modifier.toggleable(
value = isChecked,
onValueChange = { isChecked = it },
role = Role.Switch
)
Box(modifier = Modifier.fillMaxSize()) {
val rowModifier = toggleModifier
.padding(16.dp)
.align(Alignment.Center)
Row(modifier = rowModifier) {
Text(text = "Sometext")
Switch(checked = isChecked, onCheckedChange = null)
}
}
The second idea was to combine the text and the switch with mergeDescendants, but they are selected separately:
var isChecked by remember { mutableStateOf(false) }
val toggleModifier =
Modifier.semantics(mergeDescendants = true) {}
Box(modifier = Modifier.fillMaxSize()) {
val rowModifier = toggleModifier
.padding(16.dp)
.align(Alignment.Center)
Row(modifier = rowModifier) {
Text(text = "Sometext")
Switch(checked = isChecked, onCheckedChange = { isChecked = !isChecked })
}
}