From 591b1f2f9162c8bc5fb448c4202cd9b2d6938685 Mon Sep 17 00:00:00 2001 From: Ege Feyzioglu Date: Thu, 30 Jul 2026 10:01:14 -0400 Subject: [PATCH 1/2] fix(mobile): keep Android composer caret visible --- .../t3composereditor/T3ComposerEditorView.kt | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt index 3010b5240997c..875c35b0682ab 100644 --- a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt +++ b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt @@ -95,10 +95,14 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( ), ) emitContentSizeIfNeeded() + editor.keepSelectionVisible() } }, ) - editor.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> emitContentSizeIfNeeded() } + editor.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> + emitContentSizeIfNeeded() + editor.keepSelectionVisible() + } addView( editor, LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT), @@ -214,6 +218,10 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( fun setScrollEnabled(scrollEnabled: Boolean) { editor.isVerticalScrollBarEnabled = scrollEnabled + editor.scrollEnabled = scrollEnabled + if (scrollEnabled) { + editor.keepSelectionVisible() + } } fun setAutoFocus(autoFocus: Boolean) { @@ -256,6 +264,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView( // state, so a no-op assignment must be skipped. if (editor.selectionStart == safeStart && editor.selectionEnd == safeEnd) return editor.setSelection(safeStart, safeEnd) + editor.keepSelectionVisible() } private fun updateInputFlags() { @@ -457,6 +466,24 @@ private fun parseTokens(value: String): List = try { private class SelectionAwareEditText(context: Context) : EditText(context) { var selectionListener: ((Int, Int) -> Unit)? = null var pasteImagesListener: ((List) -> Unit)? = null + var scrollEnabled = true + private val keepSelectionVisibleRunnable = Runnable { + if (scrollEnabled && isFocused) { + bringPointIntoView(selectionEnd.coerceAtLeast(0)) + } + } + + override fun scrollTo(x: Int, y: Int) { + if (scrollEnabled) { + super.scrollTo(x, y) + } + } + + fun keepSelectionVisible() { + if (!scrollEnabled) return + removeCallbacks(keepSelectionVisibleRunnable) + post(keepSelectionVisibleRunnable) + } override fun onSelectionChanged(selStart: Int, selEnd: Int) { super.onSelectionChanged(selStart, selEnd) From dcac2e70451a642fcf9bdf856ca67f9c470bc356 Mon Sep 17 00:00:00 2001 From: Ege Feyzioglu Date: Thu, 30 Jul 2026 07:17:10 -0400 Subject: [PATCH 2/2] fix(mobile): follow Android composer caret while typing --- .../t3composereditor/T3ComposerEditorView.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt index 875c35b0682ab..163bde2f9702e 100644 --- a/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt +++ b/apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt @@ -469,7 +469,23 @@ private class SelectionAwareEditText(context: Context) : EditText(context) { var scrollEnabled = true private val keepSelectionVisibleRunnable = Runnable { if (scrollEnabled && isFocused) { - bringPointIntoView(selectionEnd.coerceAtLeast(0)) + val textLayout = layout ?: return@Runnable + val offset = selectionEnd.coerceIn(0, text?.length ?: 0) + val line = textLayout.getLineForOffset(offset) + val viewportHeight = height - compoundPaddingTop - compoundPaddingBottom + if (viewportHeight <= 0) return@Runnable + + val lineTop = textLayout.getLineTop(line) + val lineBottom = textLayout.getLineBottom(line) + val targetScrollY = when { + lineBottom > scrollY + viewportHeight -> lineBottom - viewportHeight + lineTop < scrollY -> lineTop + else -> scrollY + }.coerceIn(0, (textLayout.height - viewportHeight).coerceAtLeast(0)) + + if (targetScrollY != scrollY) { + scrollTo(scrollX, targetScrollY) + } } } @@ -488,6 +504,9 @@ private class SelectionAwareEditText(context: Context) : EditText(context) { override fun onSelectionChanged(selStart: Int, selEnd: Int) { super.onSelectionChanged(selStart, selEnd) selectionListener?.invoke(selStart, selEnd) + if (isAttachedToWindow) { + keepSelectionVisible() + } } override fun onTextContextMenuItem(id: Int): Boolean {