fix(mobile): Android chip taps open the chip from either half #33126
Merged
maria-rcksmerged 5 commits into
main fromrefs/pull/33126/head·merged by juliusmarminge View on GitHubShowing 1 changed file with 21 additions and 2 deletions.
x
21 additions and 2 deletions+21-2apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.ktModifiedView file
@@ -131,8 +131,9 @@
- offset >= it.start &&
- offset < it.end
+ offset in it.start..it.end &&
+ it.end <= editor.length() &&
+ chipContains(it, event.x, event.y)
🟠 High t3composereditor/T3ComposerEditorView.kt:135
After a trailing chip is deleted, a tap at its former start can crash the touch handler with IndexOutOfBoundsException on Android 16: chipContains calls getPrimaryHorizontal(token.end) using stale token bounds before the later text/source check runs. Validate the token’s bounds and source against editor.text before calling chipContains.
Suggested change
136+ it.start >= 0 &&
137+ it.end <= editor.length() &&
138+ it.end > it.start &&
139+ editor.text.substring(it.start, it.end) == it.source &&
140+ chipContains(it, event.x, event.y)
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt around line 135:
After a trailing chip is deleted, a tap at its former start can crash the touch handler with `IndexOutOfBoundsException` on Android 16: `chipContains` calls `getPrimaryHorizontal(token.end)` using stale token bounds before the later text/source check runs. Validate the token’s bounds and source against `editor.text` before calling `chipContains`.
Note
Written by claude-opus-5-5 on behalf of Maria
Fixed in 8819120992: a token whose end is past the current text is skipped before chipContains measures it. The existing source check after the match still guards the press event, so I kept the guard to the one bound that can throw.
@@ -450,6 +451,24 @@
+ // A chip is one replacement span, so a tap on its right half reports the offset at its end,
+ // and a tap below the last line clamps to it; only the chip's drawn bounds count.
+ private fun chipContains(token: ComposerToken, viewX: Float, viewY: Float): Boolean {
+ val layout = editor.layout ?: return false
+ val x = viewX - editor.totalPaddingLeft + editor.scrollX
+ val y = viewY - editor.totalPaddingTop + editor.scrollY
+ val line = layout.getLineForOffset(token.start)
+ val left = layout.getPrimaryHorizontal(token.start)
+ val right =
+ if (layout.getLineForOffset(token.end) == line) {
+ layout.getPrimaryHorizontal(token.end)
+ } else {