Skip to content

Commit faca193

Browse files
committed
fix(mobile): Android chip end taps must land on the chip's line
1 parent d114576 commit faca193

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
132132
tokens.firstOrNull {
133133
(it.type == "context" || it.type == "mention" || it.type == "skill") &&
134134
offset >= it.start &&
135-
(offset < it.end || (offset == it.end && chipContainsX(it, event.x)))
135+
(offset < it.end || (offset == it.end && chipContains(it, event.x, event.y)))
136136
}
137137
?: return false
138138
if (token.end <= editor.length() &&
@@ -451,10 +451,13 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
451451
}
452452

453453
// A chip is one replacement span, so a tap on its right half reports the offset at its end.
454-
private fun chipContainsX(token: ComposerToken, viewX: Float): Boolean {
454+
// Taps below the last line clamp to it, so the drawn line's bounds are checked too.
455+
private fun chipContains(token: ComposerToken, viewX: Float, viewY: Float): Boolean {
455456
val layout = editor.layout ?: return false
456457
val x = viewX - editor.totalPaddingLeft + editor.scrollX
458+
val y = viewY - editor.totalPaddingTop + editor.scrollY
457459
val line = layout.getLineForOffset(token.start)
460+
if (y < layout.getLineTop(line) || y > layout.getLineBottom(line)) return false
458461
val left = layout.getPrimaryHorizontal(token.start)
459462
val right =
460463
if (layout.getLineForOffset(token.end) == line) {

0 commit comments

Comments
 (0)