Modern Apps git

← Modern-Apps.git

library: announce achievement unlocks to TalkBack (#ux-audit)

Commit
43e589059db426816627a4fc348f3aa4c8942c4e
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:22 UTC (23 days ago)
Parents
f954f74
Symptom: with TalkBack on, an unlocked achievement was silent. The
toast slid in and out at the top of the screen with nothing spoken,
so a screen-reader user only found out by stumbling onto the card
with touch exploration during its few seconds on screen - or never.

Root cause: the toast card carried no live-region semantics, so its
appearance produced no accessibility announcement.

Fix: the card is marked semantics { liveRegion = Polite }. The card is
clickable (previous commit), which merges its texts into one node, so
TalkBack reads "Achievement Unlocked!, <name>, <description>" once
when it appears. Polite rather than assertive so it waits for current
speech instead of cutting off game feedback. Together with the
accessibility-recommended timeout from the duration change, users who
need more time to hear it also get the card for longer.

User-visible effect: TalkBack users hear each unlock, including each
one in a queued burst, as it appears.

Verification: AchievementNotificationTest asserts the merged card node
(found by the achievement name) has LiveRegion = Polite.

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/AchievementNotification.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/AchievementNotification.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/AchievementNotification.ktindex 779882df6d..0b9f39de5d 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/AchievementNotification.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/AchievementNotification.kt@@ -36,6 +36,9 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalAccessibilityManager import androidx.compose.ui.res.painterResource+import androidx.compose.ui.semantics.LiveRegionMode+import androidx.compose.ui.semantics.liveRegion+import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.res.stringResource@@ -55,6 +58,8 @@ import kotlinx.coroutines.flow.first  * and sides of safe drawing by default), plus a small margin. Insets an ancestor has already consumed  * are not applied twice.  *+ * It is a polite live region, so TalkBack announces the unlock when it appears.+ *  * [onDismiss] runs once the exit animation has finished, which is when the caller should move on to the  * next queued unlock. Each [achievement] gets a fresh toast, so a queue that advances in place shows  * the next one from the start.@@ -103,6 +108,9 @@ private fun AchievementToast(achievement: Achievement, onDismiss: () -> Unit, wi         Card(             modifier = Modifier                 .fillMaxWidth()+                // TalkBack reads the merged card ("Achievement Unlocked!, <name>, <description>") when it+                // appears, without interrupting whatever it is already saying.+                .semantics { liveRegion = LiveRegionMode.Polite }                 // Tap to dismiss; swipe up past the threshold to dismiss too. Both play the same exit                 // animation as the timeout.                 .clickable(onClickLabel = stringResource(R.string.dismiss), onClick = hide)
library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.ktindex 663231e3c2..38e2f4c0a6 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/AchievementNotificationTest.kt@@ -11,6 +11,10 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.platform.testTag+import androidx.compose.ui.semantics.LiveRegionMode+import androidx.compose.ui.semantics.SemanticsProperties+import androidx.compose.ui.test.SemanticsMatcher+import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.click import androidx.compose.ui.test.getUnclippedBoundsInRoot@@ -122,6 +126,14 @@ class AchievementNotificationTest {         assertEquals(40f, (inset - flush).value, 0.5f, "the whole card moves down by the inset")     } +    @Test+    fun `TalkBack announces the unlock politely`() {+        setToastOverScreen()+        rule.onNodeWithText("First win").assert(+            SemanticsMatcher.expectValue(SemanticsProperties.LiveRegion, LiveRegionMode.Polite),+        )+    }+     private companion object {         const val ROOT = "root"