Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
private var keyListener: InternalKeyListener? = null
private var detectScrollMovement = false
private var onKeyPress = false
private var selectionWasCollapsed = true
private val textAttributes: TextAttributes
private var typefaceDirty = false
private var fontFamily: String? = null
Expand Down Expand Up @@ -492,13 +493,29 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
if (selectionWatcher != null && hasFocus()) {
selectionWatcher?.onSelectionChanged(selStart, selEnd)
}
maybeShowSoftKeyboardForSelection(selStart, selEnd)
}

override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
super.onFocusChanged(focused, direction, previouslyFocusedRect)
if (focused && selectionWatcher != null) {
selectionWatcher?.onSelectionChanged(selectionStart, selectionEnd)
}
if (focused) {
maybeShowSoftKeyboardForSelection(selectionStart, selectionEnd)
}
}

private fun maybeShowSoftKeyboardForSelection(selectionStart: Int, selectionEnd: Int) {
if (!hasFocus() || !showSoftInputOnFocus) {
return
}

val selectionIsCollapsed = selectionStart == selectionEnd
if (!selectionIsCollapsed && selectionWasCollapsed) {
showSoftKeyboard()
}
selectionWasCollapsed = selectionIsCollapsed
}

internal fun setSelectionWatcher(selectionWatcher: SelectionWatcher?) {
Expand Down
Loading
Loading