Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 381c5aa

Browse files
authoredFeb 17, 2021
Merge pull request #400 from android/jv/rally_a11y
[Rally] Content description, tabs, and grouping views
2 parents d6a4a72 + 2dd3282 commit 381c5aa

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed
 

‎Rally/app/src/main/java/com/example/compose/rally/ui/components/CommonUi.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import androidx.compose.ui.Alignment
3939
import androidx.compose.ui.Modifier
4040
import androidx.compose.ui.graphics.Color
4141
import androidx.compose.ui.res.stringResource
42+
import androidx.compose.ui.semantics.clearAndSetSemantics
43+
import androidx.compose.ui.semantics.contentDescription
4244
import androidx.compose.ui.unit.dp
4345
import com.example.compose.rally.R
4446
import java.text.DecimalFormat
@@ -79,8 +81,15 @@ private fun BaseRow(
7981
amount: Float,
8082
negative: Boolean
8183
) {
84+
val dollarSign = if (negative) "–$ " else "$ "
85+
val formattedAmount = formatAmount(amount)
8286
Row(
83-
modifier = Modifier.height(68.dp),
87+
modifier = Modifier
88+
.height(68.dp)
89+
.clearAndSetSemantics {
90+
contentDescription =
91+
"$title account ending in ${subtitle.takeLast(4)}, current balance $dollarSign$formattedAmount"
92+
},
8493
verticalAlignment = Alignment.CenterVertically
8594
) {
8695
val typography = MaterialTheme.typography
@@ -100,14 +109,12 @@ private fun BaseRow(
100109
horizontalArrangement = Arrangement.SpaceBetween
101110
) {
102111
Text(
103-
text = if (negative) "–$ " else "$ ",
112+
text = dollarSign,
104113
style = typography.h6,
105114
modifier = Modifier.align(Alignment.CenterVertically)
106115
)
107116
Text(
108-
text = formatAmount(
109-
amount
110-
),
117+
text = formattedAmount,
111118
style = typography.h6,
112119
modifier = Modifier.align(Alignment.CenterVertically)
113120
)

‎Rally/app/src/main/java/com/example/compose/rally/ui/components/TopAppBar.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import androidx.compose.runtime.remember
4040
import androidx.compose.ui.Modifier
4141
import androidx.compose.ui.graphics.Color
4242
import androidx.compose.ui.graphics.vector.ImageVector
43+
import androidx.compose.ui.semantics.Role
44+
import androidx.compose.ui.semantics.clearAndSetSemantics
4345
import androidx.compose.ui.unit.Dp
4446
import androidx.compose.ui.unit.dp
4547
import com.example.compose.rally.RallyScreen
@@ -96,6 +98,7 @@ private fun RallyTab(
9698
.selectable(
9799
selected = selected,
98100
onClick = onSelected,
101+
role = Role.Tab,
99102
interactionSource = remember { MutableInteractionSource() },
100103
indication = rememberRipple(
101104
bounded = false,
@@ -104,10 +107,10 @@ private fun RallyTab(
104107
)
105108
)
106109
) {
107-
Icon(imageVector = icon, contentDescription = null, tint = tabTintColor)
110+
Icon(imageVector = icon, contentDescription = text, tint = tabTintColor)
108111
if (selected) {
109112
Spacer(Modifier.width(12.dp))
110-
Text(text, color = tabTintColor)
113+
Text(text, color = tabTintColor, modifier = Modifier.clearAndSetSemantics {})
111114
}
112115
}
113116
}

‎Rally/app/src/main/java/com/example/compose/rally/ui/overview/OverviewScreen.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import androidx.compose.ui.Alignment
4444
import androidx.compose.ui.Modifier
4545
import androidx.compose.ui.graphics.Color
4646
import androidx.compose.ui.res.stringResource
47+
import androidx.compose.ui.semantics.clearAndSetSemantics
48+
import androidx.compose.ui.semantics.semantics
4749
import androidx.compose.ui.unit.dp
4850
import com.example.compose.rally.R
4951
import com.example.compose.rally.RallyScreen
@@ -128,7 +130,13 @@ private fun AlertHeader(onClickSeeAll: () -> Unit) {
128130
@Composable
129131
private fun AlertItem(message: String) {
130132
Row(
131-
modifier = Modifier.padding(RallyDefaultPadding),
133+
modifier = Modifier
134+
.padding(RallyDefaultPadding)
135+
// Regard the whole row as one semantics node. This way each row will receive focus as
136+
// a whole and the focus bounds will be around the whole row content. The semantics
137+
// properties of the descendants will be merged. If we'd use clearAndSetSemantics instead,
138+
// we'd have to define the semantics properties explicitly.
139+
.semantics(mergeDescendants = true) {},
132140
horizontalArrangement = Arrangement.SpaceBetween
133141
) {
134142
Text(
@@ -138,9 +146,11 @@ private fun AlertItem(message: String) {
138146
)
139147
IconButton(
140148
onClick = {},
141-
modifier = Modifier.align(Alignment.Top)
149+
modifier = Modifier
150+
.align(Alignment.Top)
151+
.clearAndSetSemantics {}
142152
) {
143-
Icon(Icons.Filled.Sort, contentDescription = stringResource(id = R.string.sort))
153+
Icon(Icons.Filled.Sort, contentDescription = null)
144154
}
145155
}
146156
}
@@ -193,6 +203,7 @@ private fun <T> OverViewDivider(
193203
}
194204
}
195205
}
206+
196207
/**
197208
* The Accounts card within the Rally Overview screen.
198209
*/
@@ -217,6 +228,7 @@ private fun AccountsCard(onScreenChange: (RallyScreen) -> Unit) {
217228
)
218229
}
219230
}
231+
220232
/**
221233
* The Bills card within the Rally Overview screen.
222234
*/

0 commit comments

Comments
 (0)
Please sign in to comment.