Skip to content

Commit d8b735f

Browse files
Revert "Improve accessibility to ForYou topics (#1309)" (#1732)
This reverts commit 4854419.
1 parent b9105c6 commit d8b735f

File tree

4 files changed

+27
-82
lines changed

4 files changed

+27
-82
lines changed

app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ package com.google.samples.apps.nowinandroid.ui
1818

1919
import androidx.compose.ui.semantics.SemanticsActions.ScrollBy
2020
import androidx.compose.ui.test.assertCountEquals
21-
import androidx.compose.ui.test.assertIsDisplayed
22-
import androidx.compose.ui.test.assertIsNotDisplayed
21+
import androidx.compose.ui.test.assertIsOn
2322
import androidx.compose.ui.test.assertIsSelected
2423
import androidx.compose.ui.test.hasTestTag
2524
import androidx.compose.ui.test.hasText
@@ -88,8 +87,6 @@ class NavigationTest {
8887
private val forYou by composeTestRule.stringResource(FeatureForyouR.string.feature_foryou_title)
8988
private val interests by composeTestRule.stringResource(FeatureSearchR.string.feature_search_interests)
9089
private val sampleTopic = "Headlines"
91-
private val sampleTopicCheckIconDescription = "Headlines checked"
92-
private val sampleTopicAddIconDescription = "Headlines add"
9390
private val appName by composeTestRule.stringResource(R.string.app_name)
9491
private val saved by composeTestRule.stringResource(BookmarksR.string.feature_bookmarks_title)
9592
private val settings by composeTestRule.stringResource(SettingsR.string.feature_settings_top_app_bar_action_icon_description)
@@ -118,20 +115,13 @@ class NavigationTest {
118115
fun navigationBar_navigateToPreviouslySelectedTab_restoresContent() {
119116
composeTestRule.apply {
120117
// GIVEN the user follows a topic
121-
onNodeWithContentDescription(sampleTopic).performClick()
118+
onNodeWithText(sampleTopic).performClick()
122119
// WHEN the user navigates to the Interests destination
123120
onNodeWithText(interests).performClick()
124121
// AND the user navigates to the For You destination
125122
onNodeWithText(forYou).performClick()
126123
// THEN the state of the For You destination is restored
127-
onNodeWithContentDescription(
128-
sampleTopicCheckIconDescription,
129-
useUnmergedTree = true,
130-
).assertIsDisplayed()
131-
onNodeWithContentDescription(
132-
sampleTopicAddIconDescription,
133-
useUnmergedTree = true,
134-
).assertIsNotDisplayed()
124+
onNodeWithContentDescription(sampleTopic).assertIsOn()
135125
}
136126
}
137127

@@ -142,18 +132,11 @@ class NavigationTest {
142132
fun navigationBar_reselectTab_keepsState() {
143133
composeTestRule.apply {
144134
// GIVEN the user follows a topic
145-
onNodeWithContentDescription(sampleTopic).performClick()
135+
onNodeWithText(sampleTopic).performClick()
146136
// WHEN the user taps the For You navigation bar item
147137
onNodeWithText(forYou).performClick()
148138
// THEN the state of the For You destination is restored
149-
onNodeWithContentDescription(
150-
sampleTopicCheckIconDescription,
151-
useUnmergedTree = true,
152-
).assertIsDisplayed()
153-
onNodeWithContentDescription(
154-
sampleTopicAddIconDescription,
155-
useUnmergedTree = true,
156-
).assertIsNotDisplayed()
139+
onNodeWithContentDescription(sampleTopic).assertIsOn()
157140
}
158141
}
159142

feature/foryou/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ForYouScreenTest {
128128

129129
testData.forEach { testTopic ->
130130
composeTestRule
131-
.onNodeWithContentDescription(testTopic.topic.name)
131+
.onNodeWithText(testTopic.topic.name)
132132
.assertExists()
133133
.assertHasClickAction()
134134
}
@@ -175,7 +175,7 @@ class ForYouScreenTest {
175175

176176
followableTopicTestData.forEach { testTopic ->
177177
composeTestRule
178-
.onNodeWithContentDescription(testTopic.topic.name)
178+
.onNodeWithText(testTopic.topic.name)
179179
.assertExists()
180180
.assertHasClickAction()
181181
}

feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ import androidx.compose.ui.platform.LocalInspectionMode
7575
import androidx.compose.ui.platform.testTag
7676
import androidx.compose.ui.res.painterResource
7777
import androidx.compose.ui.res.stringResource
78-
import androidx.compose.ui.semantics.clearAndSetSemantics
79-
import androidx.compose.ui.semantics.contentDescription
80-
import androidx.compose.ui.semantics.semantics
81-
import androidx.compose.ui.semantics.stateDescription
82-
import androidx.compose.ui.semantics.toggleableState
83-
import androidx.compose.ui.state.ToggleableState.Off
84-
import androidx.compose.ui.state.ToggleableState.On
8578
import androidx.compose.ui.text.style.TextAlign
8679
import androidx.compose.ui.tooling.preview.PreviewParameter
8780
import androidx.compose.ui.unit.dp
@@ -275,30 +268,23 @@ private fun LazyStaggeredGridScope.onboarding(
275268

276269
is OnboardingUiState.Shown -> {
277270
item(span = StaggeredGridItemSpan.FullLine, contentType = "onboarding") {
278-
Column(
279-
modifier = interestsItemModifier,
280-
) {
281-
Column(
271+
Column(modifier = interestsItemModifier) {
272+
Text(
273+
text = stringResource(R.string.feature_foryou_onboarding_guidance_title),
274+
textAlign = TextAlign.Center,
282275
modifier = Modifier
283-
.semantics(mergeDescendants = true) { },
284-
) {
285-
Text(
286-
text = stringResource(R.string.feature_foryou_onboarding_guidance_title),
287-
textAlign = TextAlign.Center,
288-
modifier = Modifier
289-
.fillMaxWidth()
290-
.padding(top = 24.dp),
291-
style = MaterialTheme.typography.titleMedium,
292-
)
293-
Text(
294-
text = stringResource(R.string.feature_foryou_onboarding_guidance_subtitle),
295-
modifier = Modifier
296-
.fillMaxWidth()
297-
.padding(top = 8.dp, start = 24.dp, end = 24.dp),
298-
textAlign = TextAlign.Center,
299-
style = MaterialTheme.typography.bodyMedium,
300-
)
301-
}
276+
.fillMaxWidth()
277+
.padding(top = 24.dp),
278+
style = MaterialTheme.typography.titleMedium,
279+
)
280+
Text(
281+
text = stringResource(R.string.feature_foryou_onboarding_guidance_subtitle),
282+
modifier = Modifier
283+
.fillMaxWidth()
284+
.padding(top = 8.dp, start = 24.dp, end = 24.dp),
285+
textAlign = TextAlign.Center,
286+
style = MaterialTheme.typography.bodyMedium,
287+
)
302288
TopicSelection(
303289
onboardingUiState,
304290
onTopicCheckedChanged,
@@ -398,21 +384,7 @@ private fun SingleTopicButton(
398384
Surface(
399385
modifier = Modifier
400386
.width(312.dp)
401-
.heightIn(min = 56.dp)
402-
.semantics(mergeDescendants = true) {
403-
toggleableState = if (isSelected) {
404-
On
405-
} else {
406-
Off
407-
}
408-
stateDescription = if (isSelected) {
409-
"Following"
410-
} else {
411-
"Not Following"
412-
}
413-
414-
contentDescription = name
415-
},
387+
.heightIn(min = 56.dp),
416388
shape = RoundedCornerShape(corner = CornerSize(8.dp)),
417389
color = MaterialTheme.colorScheme.surface,
418390
selected = isSelected,
@@ -422,9 +394,7 @@ private fun SingleTopicButton(
422394
) {
423395
Row(
424396
verticalAlignment = Alignment.CenterVertically,
425-
modifier = Modifier
426-
.padding(start = 12.dp, end = 8.dp)
427-
.clearAndSetSemantics { },
397+
modifier = Modifier.padding(start = 12.dp, end = 8.dp),
428398
) {
429399
TopicIcon(
430400
imageUrl = imageUrl,
@@ -443,19 +413,13 @@ private fun SingleTopicButton(
443413
icon = {
444414
Icon(
445415
imageVector = NiaIcons.Add,
446-
contentDescription = stringResource(
447-
id = R.string.feature_foryou_topic_icon_add,
448-
name,
449-
),
416+
contentDescription = name,
450417
)
451418
},
452419
checkedIcon = {
453420
Icon(
454421
imageVector = NiaIcons.Check,
455-
contentDescription = stringResource(
456-
id = R.string.feature_foryou_topic_icon_checked,
457-
name,
458-
),
422+
contentDescription = name,
459423
)
460424
},
461425
)

feature/foryou/src/main/res/values/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
<string name="feature_foryou_navigate_up">Navigate up</string>
2222
<string name="feature_foryou_onboarding_guidance_title">What are you interested in?</string>
2323
<string name="feature_foryou_onboarding_guidance_subtitle">Updates from topics you follow will appear here. Follow some things to get started.</string>
24-
<string name="feature_foryou_topic_icon_checked">%s checked</string>
25-
<string name="feature_foryou_topic_icon_add">%s add</string>
2624

2725
</resources>

0 commit comments

Comments
 (0)