Skip to content

Commit

Permalink
Make TalkBack inform about the selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Dec 10, 2024
1 parent 3fbbb5b commit c51a6ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.semantics.CollectionInfo
import androidx.compose.ui.semantics.CollectionItemInfo
import androidx.compose.ui.semantics.collectionInfo
import androidx.compose.ui.semantics.collectionItemInfo
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
Expand Down Expand Up @@ -239,6 +240,7 @@ private fun ListsMenu(
isMenuVisible = false
},
modifier = Modifier.semantics {
selected = isSelected
collectionItemInfo = CollectionItemInfo(
rowIndex = (index * servers.size) + envIndex,
rowSpan = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import androidx.compose.ui.semantics.CollectionItemInfo
import androidx.compose.ui.semantics.collectionInfo
import androidx.compose.ui.semantics.collectionItemInfo
import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
Expand Down Expand Up @@ -304,21 +305,24 @@ private fun SearchInput(
)
) {
bus.forEachIndexed { index, bu ->
val isSelected = selectedBu == bu

DropdownMenuItem(
text = { BuLabel(bu) },
onClick = {
onBuChange(bu)
showBuSelector = false
},
modifier = Modifier.semantics {
selected = isSelected
collectionItemInfo = CollectionItemInfo(
rowIndex = index,
rowSpan = 1,
columnIndex = 1,
columnSpan = 1,
)
},
trailingIcon = if (selectedBu == bu) {
trailingIcon = if (isSelected) {
{
Icon(
imageVector = Icons.Default.Check,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.compose.ui.semantics.collectionInfo
import androidx.compose.ui.semantics.collectionItemInfo
import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpOffset
Expand Down Expand Up @@ -298,13 +299,16 @@ private fun <T> DropdownSetting(
offset = dropdownOffset,
) {
entries.forEachIndexed { index, entry ->
val isSelected = entry == selectedEntry

DropdownMenuItem(
text = { Text(text = entry.toString()) },
onClick = {
onEntrySelected(entry)
showDropdownMenu = false
},
modifier = Modifier.semantics {
selected = isSelected
collectionItemInfo = CollectionItemInfo(
rowIndex = index,
rowSpan = 1,
Expand All @@ -313,7 +317,7 @@ private fun <T> DropdownSetting(
)
},
leadingIcon = {
AnimatedVisibility(entry == selectedEntry) {
AnimatedVisibility(isSelected) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.semantics.CollectionInfo
import androidx.compose.ui.semantics.CollectionItemInfo
import androidx.compose.ui.semantics.collectionInfo
import androidx.compose.ui.semantics.collectionItemInfo
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.DpOffset
import androidx.lifecycle.compose.LifecycleResumeEffect
Expand Down Expand Up @@ -142,6 +143,8 @@ fun CustomPlaybackSettingsShowcase(
offset = menuOffset,
) {
repeatModes.forEachIndexed { index, (repeatMode, repeatModeLabel) ->
val isSelected = index == selectedRepeatModeIndex

DropdownMenuItem(
text = { Text(text = repeatModeLabel) },
onClick = {
Expand All @@ -150,6 +153,7 @@ fun CustomPlaybackSettingsShowcase(
showRepeatModeMenu = false
},
modifier = Modifier.semantics {
selected = isSelected
collectionItemInfo = CollectionItemInfo(
rowIndex = index,
rowSpan = 1,
Expand All @@ -158,7 +162,7 @@ fun CustomPlaybackSettingsShowcase(
)
},
leadingIcon = {
AnimatedVisibility(index == selectedRepeatModeIndex) {
AnimatedVisibility(isSelected) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null,
Expand Down

0 comments on commit c51a6ab

Please sign in to comment.