Expected behaviour:
- When user toggles on any component say a button in this case, then when the state is updated or changed automatically talk back should read/announce the updated state value.
Reproduce steps:
- Create a button BookmarkButton using compose.
- Set false as default state. Now customize the state to true programmatically.
- Based on the state will assign the custom read string to
stateDescriptionparam. - Test with TalkBack (12.1) and observe it does not read out updated state description as expected.
Tested on devices: OnePlus 8 API 31, Emulator Pixel 4a API 31 and Pixel 4a API 32
@Composable
fun BookmarkButton(
isBookmarked: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
contentAlpha: Float = ContentAlpha.high
) {
var isChecked by remember { mutableStateOf(false) }
CompositionLocalProvider(LocalContentAlpha provides contentAlpha) {
IconToggleButton(
checked = isChecked,
onCheckedChange = { isChecked = !isChecked },
modifier = modifier.semantics {
this.stateDescription =
if (isChecked) "Yes added to book mark" else "Removed from bookmark"
}
) {
Icon(
imageVector = if (isChecked) Icons.Filled.Bookmark else Icons.Filled.BookmarkBorder,
contentDescription = null // handled by click label of parent
)
}
}
}
Can this talkback feature when any state is updated be achieved using this approach or any alternate solution available for the same?