Modern Apps git

← Modern-Apps.git

games-minesweeper: expose board cell tap actions to screen readers

Commit
06a2430018da66ed7ee5ee8abab4a6f1ac6d00e3
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:43 UTC (28 days ago)
Parents
eec3244
Each field cell announced itself to accessibility services ("Row 1,
column 1, Covered") but exposed no activation action, so a TalkBack
user could hear the board without being able to play it: double-tap
does nothing without a semantics click action, and the gestures live
in pointerInput, which installs none.

Add semantics-only onClick/onLongClick actions to the cell semantics
block, wired to the same onTap/onLongPress handlers (with the same
long-press haptic). Deliberately not a clickable/combinedClickable
modifier: that would also deliver a tap on press-and-hold and break
the tap/long-press split the detectTapGestures KDoc calls out, while
semantics actions change nothing visually or gesturally.

User-visible effect: TalkBack double-tap now digs/flags the focused
cell and double-tap-and-hold performs the long-press gesture, making
the field playable with a screen reader.

Verified with :games:minesweeper:testDevUnitTest (all 61 tests pass),
including the new gridCellsExposeClickActionsForScreenReaders test,
which asserts the click action exists and that both semantics actions
reach the tap/long-press handlers.

Diff

games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.ktindex 882c4d1ae0..2f8f2d706c 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt@@ -21,6 +21,8 @@ import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.onClick+import androidx.compose.ui.semantics.onLongClick import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp@@ -125,7 +127,18 @@ private fun MineCell(                     },                 )             }-            .clearAndSetSemantics { contentDescription = "$position, $stateWord" },+            .clearAndSetSemantics {+                contentDescription = "$position, $stateWord"+                // Screen-reader activation. Semantics-only on purpose: a clickable+                // modifier would also deliver a tap on press-and-hold and break the+                // tap/long-press split that detectTapGestures above preserves.+                onClick { onTap(); true }+                onLongClick {+                    haptics.performHapticFeedback(HapticFeedbackType.LongPress)+                    onLongPress()+                    true+                }+            },         contentAlignment = Alignment.Center,     ) {         when {
games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt
diff --git a/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt b/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.ktindex 34d276cf8d..f67f275a90 100644--- a/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt+++ b/games/minesweeper/src/test/java/com/vayunmathur/games/minesweeper/ui/MinesweeperBoardTest.kt@@ -1,10 +1,13 @@ package com.vayunmathur.games.minesweeper.ui +import androidx.compose.ui.test.assertHasClickAction import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performSemanticsAction+import androidx.compose.ui.semantics.SemanticsActions import androidx.test.core.app.ApplicationProvider import com.vayunmathur.games.minesweeper.R import com.vayunmathur.games.minesweeper.data.BoardSize@@ -63,6 +66,23 @@ class MinesweeperBoardTest {         assertEquals(0, tapped)     } +    @Test+    fun gridCellsExposeClickActionsForScreenReaders() {+        var tapped = -1+        var longPressed = -1+        composeRule.setContent {+            MineFieldGrid(field(), onTap = { tapped = it }, onLongPress = { longPressed = it })+        }+        // The description alone only lets TalkBack announce the cell; activation+        // needs the click actions too, or the board is heard but not playable.+        val cell = composeRule.onNodeWithContentDescription("Row 1, column 1, Covered", substring = true)+        cell.assertHasClickAction()+        cell.performSemanticsAction(SemanticsActions.OnClick)+        assertEquals(0, tapped)+        cell.performSemanticsAction(SemanticsActions.OnLongClick)+        assertEquals(0, longPressed)+    }+     @Test     fun gridRevealedNumberAndFlagDescriptions() {         val revealed = List(9) { it == 0 }