Skip to content

Commit

Permalink
Fixed talkback for delete dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Mar 14, 2024
1 parent 10437fa commit 233d6ce
Showing 1 changed file with 73 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.requiredHeightIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -32,7 +33,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -107,40 +111,65 @@ fun DeleteFeedDialog(
},
title = {
Box(modifier = Modifier.fillMaxWidth()) {
val stateLabel = if (selectAllSelected) {
stringResource(androidx.compose.ui.R.string.selected)
} else {
stringResource(androidx.compose.ui.R.string.not_selected)
}
val stateLabel =
if (selectAllSelected) {
stringResource(androidx.compose.ui.R.string.selected)
} else {
stringResource(androidx.compose.ui.R.string.not_selected)
}
Text(
text = stringResource(id = R.string.delete_feed),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.align(Alignment.CenterStart)
modifier = Modifier.align(Alignment.CenterStart),
)
Box(modifier = Modifier.align(Alignment.CenterEnd)) {
IconButton(onClick = { menuExpanded = true }) {
Icon(Icons.Default.MoreVert, contentDescription = stringResource(android.R.string.selectAll))
Icon(Icons.Default.MoreVert, contentDescription = stringResource(R.string.open_menu))
}

DropdownMenu(expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
DropdownMenuItem(text = {
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(checked = selectAllSelected, onCheckedChange = { checked ->
onSelectAll(checked)
menuExpanded = false
}, modifier = Modifier.clearAndSetSemantics { })
Spacer(modifier = Modifier.width(4.dp))
Text(
text = stringResource(id = android.R.string.selectAll),
style = MaterialTheme.typography.titleMedium,
)
}
}, onClick = {
onSelectAll(!selectAllSelected)
menuExpanded = false
}, modifier = Modifier.safeSemantics(mergeDescendants = true) {
stateDescription = stateLabel
})
DropdownMenuItem(
text = {
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(
checked = selectAllSelected,
onCheckedChange = { checked ->
onSelectAll(checked)
menuExpanded = false
},
modifier = Modifier.clearAndSetSemantics { },
)
Spacer(modifier = Modifier.width(4.dp))
Text(
text = stringResource(id = android.R.string.selectAll),
style = MaterialTheme.typography.titleMedium,
)
}
},
onClick = {
onSelectAll(!selectAllSelected)
menuExpanded = false
},
modifier =
Modifier.safeSemantics(mergeDescendants = true) {
stateDescription = stateLabel
},
)
val closeMenuText = stringResource(id = R.string.close_menu)
// Hidden button for TalkBack
DropdownMenuItem(
onClick = {
menuExpanded = false
},
text = {},
modifier =
Modifier
.height(0.dp)
.safeSemantics {
contentDescription = closeMenuText
role = Role.Button
},
)
}
}
}
Expand All @@ -153,24 +182,25 @@ fun DeleteFeedDialog(
feeds.item,
key = { feed -> feed.id },
) { feed ->
val stateLabel = if (isChecked(feed.id)) {
stringResource(androidx.compose.ui.R.string.selected)
} else {
stringResource(androidx.compose.ui.R.string.not_selected)
}
val stateLabel =
if (isChecked(feed.id)) {
stringResource(androidx.compose.ui.R.string.selected)
} else {
stringResource(androidx.compose.ui.R.string.not_selected)
}
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
modifier =
Modifier
.fillMaxWidth()
.requiredHeightIn(min = minimumTouchSize)
.clickable {
onToggleFeed(feed.id, !isChecked(feed.id))
}
.safeSemantics(mergeDescendants = true) {
stateDescription = stateLabel
},
Modifier
.fillMaxWidth()
.requiredHeightIn(min = minimumTouchSize)
.clickable {
onToggleFeed(feed.id, !isChecked(feed.id))
}
.safeSemantics(mergeDescendants = true) {
stateDescription = stateLabel
},
) {
Checkbox(
checked = isChecked(feed.id),
Expand Down Expand Up @@ -202,10 +232,10 @@ data class DeletableFeed(
private fun Preview() =
DeleteFeedDialog(
feeds =
immutableListHolderOf(
DeletableFeed(1, "A Feed"),
DeletableFeed(2, "Another Feed"),
),
immutableListHolderOf(
DeletableFeed(1, "A Feed"),
DeletableFeed(2, "Another Feed"),
),
onDismiss = {},
onDelete = {},
)

0 comments on commit 233d6ce

Please sign in to comment.