First attempt at improving accessibility on ForYouScreen

Change-Id: I2977a310dfd4620dd45dab97451a3863fb2f9cf4
dt/improve-accessibility
Don Turner 9 months ago
parent bd89507f10
commit ee0d486a81

@ -75,6 +75,11 @@ import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -382,20 +387,38 @@ private fun SingleTopicButton(
isSelected: Boolean, isSelected: Boolean,
onClick: (String, Boolean) -> Unit, onClick: (String, Boolean) -> Unit,
) = trace("SingleTopicButton") { ) = trace("SingleTopicButton") {
val actionLabel = "Follow or unfollow"
val toggleTopicFollowed = { onClick(topicId, !isSelected) }
val accessibleToggleTopicFollowed : () -> Boolean = {
toggleTopicFollowed()
true
}
Surface( Surface(
modifier = Modifier modifier = Modifier
.width(312.dp) .width(312.dp)
.heightIn(min = 56.dp), .heightIn(min = 56.dp)
.semantics(mergeDescendants = true) {
stateDescription = if (isSelected){
"Following"
} else {
"Not following"
}
customActions = listOf(
CustomAccessibilityAction(actionLabel, accessibleToggleTopicFollowed)
)
},
shape = RoundedCornerShape(corner = CornerSize(8.dp)), shape = RoundedCornerShape(corner = CornerSize(8.dp)),
color = MaterialTheme.colorScheme.surface, color = MaterialTheme.colorScheme.surface,
selected = isSelected, selected = isSelected,
onClick = { onClick = toggleTopicFollowed,
onClick(topicId, !isSelected)
},
) { ) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 12.dp, end = 8.dp), modifier = Modifier
.padding(start = 12.dp, end = 8.dp)
) { ) {
TopicIcon( TopicIcon(
imageUrl = imageUrl, imageUrl = imageUrl,
@ -410,19 +433,20 @@ private fun SingleTopicButton(
) )
NiaIconToggleButton( NiaIconToggleButton(
checked = isSelected, checked = isSelected,
onCheckedChange = { checked -> onClick(topicId, checked) }, onCheckedChange = { },
icon = { icon = {
Icon( Icon(
imageVector = NiaIcons.Add, imageVector = NiaIcons.Add,
contentDescription = name, contentDescription = null,
) )
}, },
checkedIcon = { checkedIcon = {
Icon( Icon(
imageVector = NiaIcons.Check, imageVector = NiaIcons.Check,
contentDescription = name, contentDescription = null,
) )
}, },
modifier = Modifier.clearAndSetSemantics { },
) )
} }
} }

Loading…
Cancel
Save