Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android.StopDetailsFilterPills): optimized screen reader text #619

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ package com.mbta.tid.mbta_app.android.component

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
Expand Down Expand Up @@ -65,13 +72,30 @@ class StopDetailsFilterPillsTest {
)
}

composeTestRule.onNodeWithText("RL", ignoreCase = true).assertIsDisplayed()
composeTestRule.onNodeWithText("M", ignoreCase = true).assertIsDisplayed()
composeTestRule
.onNodeWithText("RL", ignoreCase = true)
.assertIsDisplayed()
.assertContentDescriptionEquals("Red Line train")
.assertIsSelected()
.assert(onClickLabelContains("Remove"))

composeTestRule
.onNodeWithText("M", ignoreCase = true)
.assertIsDisplayed()
.assertIsNotSelected()
composeTestRule
.onNodeWithText(route3.shortName)
.assert(onClickLabelContains("Apply"))
.assertIsNotSelected()
.onParent()
.performScrollToNode(hasText(route3.shortName))
composeTestRule.onNodeWithText(route3.shortName).assertIsDisplayed()

composeTestRule
.onNodeWithText(route3.shortName)
.assertIsDisplayed()
.assertContentDescriptionEquals("55 bus")
.assertIsNotSelected()
.assert(onClickLabelContains("Apply"))

composeTestRule.onNodeWithText("M", ignoreCase = true).performClick()
assertTrue(filter.value?.routeId == route2.id)
Expand All @@ -80,7 +104,15 @@ class StopDetailsFilterPillsTest {
assertTrue(filter.value == null)
composeTestRule.onNodeWithText("All").assertDoesNotExist()

composeTestRule.onNodeWithText(route3.shortName).performClick()
composeTestRule
.onNodeWithText(route3.shortName)
.assert(onClickLabelContains("Apply"))
.performClick()
assertTrue(filter.value?.routeId == route3.id)
}

fun onClickLabelContains(text: String) =
SemanticsMatcher("hint matches") { node ->
node.config.getOrNull(SemanticsActions.OnClick)?.label?.contains(text) ?: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.mbta.tid.mbta_app.android.stopDetails

import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isHeading
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import com.mbta.tid.mbta_app.model.Coordinate
Expand Down Expand Up @@ -232,7 +235,8 @@ class StopDetailsViewTest {
}
}

composeTestRule.onNodeWithText("Sample Stop").assertExists()
composeTestRule.onNode(hasText("Sample Stop") and isHeading()).assertIsDisplayed()

composeTestRule.onNodeWithText("Sample Route").assertExists()
composeTestRule.onNodeWithText("Sample Headsign").assertExists()
composeTestRule.onNodeWithText("1 min").assertExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -28,7 +30,7 @@ fun SheetHeader(onClose: (() -> Unit)? = null, title: String? = null) {
if (title != null) {
Text(
title,
modifier = Modifier.padding(top = 1.dp),
modifier = Modifier.padding(top = 1.dp).semantics { heading() },
fontSize = 20.sp,
fontWeight = FontWeight.SemiBold
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mbta.tid.mbta_app.android.stopDetails

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
Expand All @@ -10,7 +11,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
Expand All @@ -23,6 +23,10 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.mbta.tid.mbta_app.android.R
import com.mbta.tid.mbta_app.android.component.RoutePill
Expand Down Expand Up @@ -53,6 +57,17 @@ fun StopDetailsFilterPills(
onTapRoutePill: (PillFilter) -> Unit,
onClearFilter: () -> Unit
) {

@Composable
fun pillHint(appliedFilter: StopDetailsFilter?, pillFilter: PillFilter): String {
val filteredToPill = appliedFilter?.routeId == pillFilter.id
return if (filteredToPill) {
stringResource(R.string.stop_filter_pills_remove_hint)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have combined stop + trip details, this state will not be possible. But in the meantime, we should represent it.

} else {
stringResource(R.string.stop_filter_pills_filter_hint)
}
}

Box(Modifier.fillMaxWidth().padding(end = 16.dp)) {
val scrollState = rememberScrollState()

Expand All @@ -68,7 +83,15 @@ fun StopDetailsFilterPills(
Modifier.padding(end = 8.dp)
.minimumInteractiveComponentSize()
.bringIntoViewRequester(requester)
.toggleable(isActive) { onTapRoutePill(filterBy) }
.clickable(
onClickLabel = pillHint(filter, filterBy),
onClick = { onTapRoutePill(filterBy) },
)
.semantics {
role = Role.Button
selected = isActive
}

when (filterBy) {
is PillFilter.ByRoute -> {
RoutePill(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">Marcar ruta favorita</string>
<string name="star_route_hint">Fijar ruta al principio de la lista</string>
<string name="stop_closed">Parada cerrada</string>
<string name="stop_filter_pills_filter_hint">Aplicar un filtro para que sólo se muestren las llegadas de esta ruta</string>
<string name="stop_filter_pills_remove_hint">Eliminar el filtro y mostrar todas las rutas</string>
<string name="suspension">Suspensión</string>
<string name="train">tren</string>
<string name="trains">trenes</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">Mete wout nan favori</string>
<string name="star_route_hint">mete wout nan tèt lis la</string>
<string name="stop_closed">Arè Fèmen</string>
<string name="stop_filter_pills_filter_hint">Aplike yon filtè pou ke sèlman arive soti nan wout sa a yo parèt</string>
<string name="stop_filter_pills_remove_hint">Retire filtè a epi montre tout wout yo</string>
<string name="suspension">Sispansyon</string>
<string name="train">tren</string>
<string name="trains">tren yo</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">Marcar rota como favorita</string>
<string name="star_route_hint">fixar rota no topo da lista</string>
<string name="stop_closed">Parada fechada</string>
<string name="stop_filter_pills_filter_hint">Aplique um filtro para que apenas as chegadas desta rota sejam exibidas</string>
<string name="stop_filter_pills_remove_hint">Remova o filtro e exiba todas as rotas</string>
<string name="suspension">Suspensão</string>
<string name="train">trem</string>
<string name="trains">trens</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">Tuyến đường sao</string>
<string name="star_route_hint">ghim đường dẫn đến đầu danh sách</string>
<string name="stop_closed">Điểm dừng bị đóng</string>
<string name="stop_filter_pills_filter_hint">Áp dụng bộ lọc để chỉ hiển thị các chuyến đến từ tuyến đường này</string>
<string name="stop_filter_pills_remove_hint">Xóa bộ lọc và hiển thị tất cả các tuyến đường</string>
<string name="suspension">Đình chỉ</string>
<string name="train">tàu</string>
<string name="trains">tàu</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">为线路添加星号</string>
<string name="star_route_hint">将路线固定到列表顶部</string>
<string name="stop_closed">站点已关闭</string>
<string name="stop_filter_pills_filter_hint">应用过滤器,以便仅显示来自该路线的到达</string>
<string name="stop_filter_pills_remove_hint">删除过滤器并显示所有路线</string>
<string name="suspension">暂停</string>
<string name="train">列车</string>
<string name="trains">列车</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<string name="star_route">為線路添加星號</string>
<string name="star_route_hint">將路線固定到清單頂部</string>
<string name="stop_closed">網站已關閉</string>
<string name="stop_filter_pills_filter_hint">應用過濾器,以便僅顯示來自該路線的到達</string>
<string name="stop_filter_pills_remove_hint">刪除過濾器並顯示所有路由</string>
<string name="suspension">暫停</string>
<string name="train">列車</string>
<string name="trains">列車</string>
Expand Down
3 changes: 3 additions & 0 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@
<string name="vehicle_schedule_time_first">%1$s arriving at %2$s scheduled</string>
<string name="vehicle_schedule_time_other">and at %1$s scheduled</string>
<string name="westbound">Westbound</string>
<string name="stop_filter_pills_filter_hint">Apply a filter so that only arrivals from this route are displayed</string>
<string name="stop_filter_pills_remove_hint">Remove the filter and display all routes</string>

</resources>
82 changes: 82 additions & 0 deletions iosApp/iosApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,47 @@
}
}
},
"Apply a filter so that only arrivals from this route are displayed" : {
"extractionState" : "manual",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Aplicar un filtro para que sólo se muestren las llegadas de esta ruta"
}
},
"ht" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Aplike yon filtè pou ke sèlman arive soti nan wout sa a yo parèt"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Aplique um filtro para que apenas as chegadas desta rota sejam exibidas"
}
},
"vi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Áp dụng bộ lọc để chỉ hiển thị các chuyến đến từ tuyến đường này"
}
},
"zh-Hans-CN" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "应用过滤器,以便仅显示来自该路线的到达"
}
},
"zh-Hant-TW" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "應用過濾器,以便僅顯示來自該路線的到達"
}
}
}
},
"Approaching" : {
"comment" : "Label for a vehicle's next stop. For example: Approaching Alewife",
"localizations" : {
Expand Down Expand Up @@ -6298,6 +6339,47 @@
}
}
},
"Remove the filter and display all routes" : {
"extractionState" : "manual",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Eliminar el filtro y mostrar todas las rutas"
}
},
"ht" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Retire filtè a epi montre tout wout yo"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Remova o filtro e exiba todas as rotas"
}
},
"vi" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Xóa bộ lọc và hiển thị tất cả các tuyến đường"
}
},
"zh-Hans-CN" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "删除过滤器并显示所有路线"
}
},
"zh-Hant-TW" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "刪除過濾器並顯示所有路由"
}
}
}
},
"Removes selected filter so that arrivals from all routes are displayed" : {
"comment" : "VoiceOver hint for the button to\nclear selected route to display all routes at a station",
"localizations" : {
Expand Down
Loading