Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): Android chip taps open the chip from either half #33126

Mergedmaria-rcksmerged 5 commits intomain fromrefs/pull/33126/headmerged by juliusmarminge View on GitHub

Showing 1 changed file with 21 additions and 2 deletions.

x
0 of 1 viewed, 1 left
21 additions and 2 deletionsapps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.ktModified
View file
@@ -131,8 +131,9 @@
val token =
tokens.firstOrNull {
(it.type == "context" || it.type == "mention" || it.type == "skill") &&
- offset >= it.start &&
- offset < it.end
+ offset in it.start..it.end &&
+ it.end <= editor.length() &&
+ chipContains(it, event.x, event.y)
Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)
?: return false
if (token.end <= editor.length() &&
@@ -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 {