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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package com.facebook.react.views.textinput

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.text.InputFilter
Expand Down Expand Up @@ -46,6 +47,15 @@ import org.robolectric.RuntimeEnvironment
@RunWith(RobolectricTestRunner::class)
class ReactTextInputPropertyTest {

private class TestReactEditText(context: Context) : ReactEditText(context) {
var showSoftKeyboardCallCount = 0

override fun showSoftKeyboard(): Boolean {
showSoftKeyboardCallCount++
return true
}
}

private lateinit var context: BridgeReactContext
private lateinit var catalystInstanceMock: CatalystInstance
private lateinit var themedContext: ThemedReactContext
Expand Down Expand Up @@ -74,6 +84,17 @@ class ReactTextInputPropertyTest {
view = manager.createViewInstance(themedContext)
}

@Test
fun testShowsSoftKeyboardWhenSelectionStartsWhileFocused() {
val textInput = TestReactEditText(themedContext)
textInput.setText("hello")
textInput.onFocusChanged(true, View.FOCUS_DOWN, null)

textInput.setSelection(1, 3)

assertThat(textInput.showSoftKeyboardCallCount).isEqualTo(1)
}

@Test
fun testAutoCorrect() {
manager.updateProperties(view, buildStyles())
Expand Down
8 changes: 4 additions & 4 deletions private/react-native-fantom/__docs__/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ hi
underlying native (Fabric/TurboModules) code, so tests stay close to real
usage and are more resilient to internal refactors. Observe results through
the public surface too — e.g. assert the rendered output
(`root.getRenderedOutput(...)`) or values delivered to public listeners
rather than reading private state.
(`root.getRenderedOutput(...)`) or values delivered to public listeners rather
than reading private state.
- When Fantom doesn't support something (a native module, a capability, a way
to observe a result, etc.), it's fine to reach into internals to work around
that limitation. Prefer a short comment explaining why the internal access is
necessary.
that limitation. Prefer a short comment explaining why the internal access
is necessary.
- Place test files in `__tests__` directories alongside the code being tested.
- Benchmark tests use the `-benchmark-itest.js` suffix.
- Use `Fantom.runTask()` to render and run synchronous operations; it ensures
Expand Down
Loading