wordmaker: make swipes and word flights correct in RTL (#ux-audit)
- Commit
34947cc0727905977ef40a3565c7d6212536b5b3- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:18 UTC (23 days ago)
- Parents
ffb04db
Symptom: in right-to-left languages (Arabic, Hebrew - both shipped
locales) a swipe selected the letter mirrored across the wheel from
the one under the finger, the trail was drawn to the wrong tiles, and
the letters of a found word flew to the wrong side of the screen.
Root cause: the letter tiles were positioned with Modifier.offset {},
which mirrors its x offset in RTL, while hit-testing and the trail
use pointer/draw coordinates, which are never mirrored. The word-place
flights had the same mismatch: their positions come from localToRoot
(absolute), but they were placed with offset {} inside a TopStart
parent, both of which mirror in RTL.
Fix:
- Letter tiles use absoluteOffset {}, so the drawn ring matches the
geometry used for hit-testing and the trail in both directions.
The rest of the row (side columns) still mirrors as normal chrome.
- The flights in WordGameOverlays are placed with absoluteOffset {}
inside a full-size Box aligned AbsoluteAlignment.TopLeft, so root
coordinates map 1:1 in either direction. The Box is only composed
while a flight is active and has no pointer input.
User-visible effect: in RTL the wheel selects exactly the tile under
the finger and found words fly into their own cells. LTR is
unchanged.
Verification: LetterChooserInputTest.rtlSwipeSelectsTheLetterUnderTheFinger
swipes C -> A -> T at their drawn positions under LayoutDirection.Rtl
and gets "CAT" (was "CST"). New WordFlightPlacementTest checks a
landed letter flight is drawn at its target cell in both LTR and RTL.Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.ktindex 1833f15129..7f955b5d41 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt@@ -5,9 +5,12 @@ package com.vayunmathur.games.wordmaker.ui import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.AnimationVector1D-import androidx.compose.foundation.layout.offset+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.absoluteOffset+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable+import androidx.compose.ui.AbsoluteAlignment import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.lerp@@ -86,34 +89,40 @@ fun WordGameOverlays( } } - animatedWord?.let { word ->- val progress = animationProgress.value- val currentOffset = lerp(wordBoxOffset, bonusButtonOffset, progress)- val alpha = 1f - progress- val animScale = 1f - (progress * 0.5f)+ // Flight positions are root coordinates (localToRoot), which never mirror. Place the+ // flights from the absolute top-left with absoluteOffset: offset {} and a TopStart parent+ // both mirror in RTL, which sent every flight to the opposite side of the screen.+ if (animatedWord == null && animatedLetters.isEmpty()) return+ Box(Modifier.fillMaxSize(), contentAlignment = AbsoluteAlignment.TopLeft) {+ animatedWord?.let { word ->+ val progress = animationProgress.value+ val currentOffset = lerp(wordBoxOffset, bonusButtonOffset, progress)+ val alpha = 1f - progress+ val animScale = 1f - (progress * 0.5f) - Text(- text = word,- fontWeight = FontWeight.Bold,- fontSize = 32.sp,- modifier = Modifier- .offset { IntOffset(currentOffset.x.toInt(), currentOffset.y.toInt()) }- .graphicsLayer(- scaleX = animScale,- scaleY = animScale,- alpha = alpha- )- )- }- val (size, fontSize) = Pair(35.dp * scale, 18.sp * scale)- animatedLetters.forEach { letter ->- val progress = letter.progress.value- val offset = lerp(letter.startOffset, letter.endOffset, progress)+ Text(+ text = word,+ fontWeight = FontWeight.Bold,+ fontSize = 32.sp,+ modifier = Modifier+ .absoluteOffset { IntOffset(currentOffset.x.toInt(), currentOffset.y.toInt()) }+ .graphicsLayer(+ scaleX = animScale,+ scaleY = animScale,+ alpha = alpha+ )+ )+ }+ val (size, fontSize) = Pair(35.dp * scale, 18.sp * scale)+ animatedLetters.forEach { letter ->+ val progress = letter.progress.value+ val offset = lerp(letter.startOffset, letter.endOffset, progress) - SurfaceText(Modifier.offset { IntOffset(offset.x.toInt(), offset.y.toInt()) },- RoundedCornerShape(4.dp * scale),- MaterialTheme.colorScheme.primary, letter.char.toString(),- Modifier, FontWeight.Bold, fontSize, size,- textColor = MaterialTheme.colorScheme.onPrimary)+ SurfaceText(Modifier.absoluteOffset { IntOffset(offset.x.toInt(), offset.y.toInt()) },+ RoundedCornerShape(4.dp * scale),+ MaterialTheme.colorScheme.primary, letter.char.toString(),+ Modifier, FontWeight.Bold, fontSize, size,+ textColor = MaterialTheme.colorScheme.onPrimary)+ } } }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.ktindex 5b1a406308..85a22d0b22 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt@@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.offset+import androidx.compose.foundation.layout.absoluteOffset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.width@@ -238,9 +238,12 @@ fun LetterChooser( val x = animatedDp((cos(angle) * radiusDp.value).dp) val y = animatedDp((sin(angle) * radiusDp.value).dp) + // absoluteOffset, not offset: offset {} mirrors x in RTL while the+ // trail and hit-testing work in unmirrored pointer coordinates, so an+ // RTL swipe selected the letter opposite the one under the finger. SurfaceText(Modifier .align(Alignment.Center)- .offset { IntOffset(x.roundToPx(), y.roundToPx()) }+ .absoluteOffset { IntOffset(x.roundToPx(), y.roundToPx()) } .onGloballyPositioned { coordinates -> onLetterPositioned(chooserLetter.id, coordinates.localToRoot(Offset.Zero)) }
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.ktnew file mode 100644index 0000000000..d54a6ec199--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt@@ -0,0 +1,68 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.animation.core.Animatable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.platform.LocalLayoutDirection+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.unit.LayoutDirection+import androidx.compose.ui.unit.dp+import com.vayunmathur.games.wordmaker.data.CrosswordData+import com.vayunmathur.games.wordmaker.platform.WordGameActions+import com.vayunmathur.games.wordmaker.ui.components.AnimatedLetter+import com.vayunmathur.library.ui.DynamicTheme+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.math.abs+import kotlin.test.Test+import kotlin.test.assertTrue++/** Where the word-place flights are drawn, in the overlay's (root-anchored) coordinate space. */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w411dp-h891dp")+class WordFlightPlacementTest {+ @get:Rule val rule = createComposeRule()++ private fun setOverlays(layoutDirection: LayoutDirection, letter: AnimatedLetter) {+ rule.setContent {+ DynamicTheme {+ CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {+ Box(Modifier.fillMaxSize()) {+ WordGameOverlays(+ showHintDialog = false, onDismissHint = {}, crosswordData = CrosswordData.fromString("CAT\n C \n T ")!!,+ foundWords = emptySet(), revealedHints = emptySet(), actions = WordGameActions.Noop,+ showBonusWordsDialog = false, onDismissBonusWords = {}, bonusWords = emptySet(),+ wordWithDefinition = null, onDismissDefinition = {}, animatedWord = null,+ animationProgress = Animatable(0f), wordBoxOffset = Offset.Zero, bonusButtonOffset = Offset.Zero,+ animatedLetters = listOf(letter), scale = 1f,+ )+ }+ }+ }+ }+ }++ private fun assertLetterTileAt(topLeft: Offset) {+ val half = with(rule.density) { 35.dp.toPx() } / 2+ val center = rule.onNodeWithText("Q").fetchSemanticsNode().boundsInRoot.center+ val expected = topLeft + Offset(half, half)+ assertTrue(abs(center.x - expected.x) < 2f && abs(center.y - expected.y) < 2f, "letter at $center, expected $expected")+ }++ @Test fun letterFlightLandsOnItsCellInLtr() {+ setOverlays(LayoutDirection.Ltr, AnimatedLetter('Q', Offset(0f, 0f), Offset(40f, 60f), Animatable(1f)))+ assertLetterTileAt(Offset(40f, 60f))+ }++ @Test fun letterFlightLandsOnItsCellInRtl() {+ // Cell positions come from localToRoot, which is never mirrored; the flight must not be either.+ setOverlays(LayoutDirection.Rtl, AnimatedLetter('Q', Offset(0f, 0f), Offset(40f, 60f), Animatable(1f)))+ assertLetterTileAt(Offset(40f, 60f))+ }+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.ktindex 242ab5e403..242540cf72 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt@@ -137,4 +137,14 @@ class LetterChooserInputTest { rule.waitForIdle() assertEquals(listOf("CA"), submitted) }++ @Test fun rtlSwipeSelectsTheLetterUnderTheFinger() {+ val submitted = mutableListOf<String>()+ setChooser(layoutDirection = LayoutDirection.Rtl) { submitted += it }+ val c = centerOf('C'); val a = centerOf('A'); val t = centerOf('T')+ rule.onRoot().performTouchInput { down(c); moveTo(c + Offset(0f, 12f)); moveTo(a); moveTo(t); up() }+ rule.waitForIdle()+ // Was "CST": tiles were drawn mirrored while hit-testing was not.+ assertEquals(listOf("CAT"), submitted)+ } }