I have a “toast” (custom composable using Box, which slides in and out after some time) notification, and I want talkback to read up the contentDescription “immediately” regardless what the user is doing or what is in the focus currently. I tried to set a focusRequest modifier and liveregion sematics, but this just doesn’t wants to work. Also tried localview.announceForAccessibility(“….”) which works but it looks kinda ugly to me. Are there a better of doing this ?
#1
fun Toast(
modifier
state
) {
val focusRequester = remember {FocusRequester()}
Box(...........)
)
{
Row{
......
Image(
painter = painterResource(id = state.icon),
contentDescription = state.message,
modifier = Modifier.weight(.5F).sematics {
liveregion = LiveRegionMode.Assetive
}.focusRequester(focusRequester).focusable(),
)
Text(text = state.messageString, modifier.clearAndSetSematics{})
}
}
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
}
#2
val localView = LocalView.current
fun toast {
LaunchedEffect(Unit) {
localView.announceForAccessibility(..........)
}
}
(ofc this not the whole code of the toast, just only wanted the “important” part)