Accessibility announcement - Jetpack Compose
In Jetpack Compose, to notify Composable
state changes, you can use the liveRegion
property from semantics
block modifier.
You can choose from two options for liveRegion
:
-
LiveRegionMode.Polite
, which waits for the speech announcement in progress to complete -
LiveRegionMode.Assertive
, which interrupts ongoing speech to immediately announce changes
If you don't specify the liveRegion
property, it indicates to Compose that updates to this field would not be announced.
var changingText by remember{ mutableStateOf("Changing text") }
Text(
text = changingText,
modifier = Modifier.semantics {
liveRegion = LiveRegionMode.Polite
contentDescription = changingText // workaround for bug
}
)
Important: there is a known issue with liveRegion
, which prevents speech announcements when the text
parameter is changed. The current workaround is to assign the same text to the contentDescription
field.