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 @@ -578,10 +578,13 @@ public open class ReactViewGroup public constructor(context: Context?) :
}

internal fun requestFocusFromJS() {
if (isAttachedToWindow) {
super.requestFocus(FOCUS_DOWN, null)
} else {
if (!isAttachedToWindow) {
focusOnAttach = true
} else if (isFocusable) {
val focusableInTouchMode = isFocusableInTouchMode
isFocusableInTouchMode = true
super.requestFocus(FOCUS_DOWN, null)
isFocusableInTouchMode = focusableInTouchMode
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.widget.FrameLayout
import androidx.test.platform.app.InstrumentationRegistry
import com.facebook.react.R
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
import com.facebook.react.uimanager.HasElevatedDescendantCache
Expand Down Expand Up @@ -212,6 +213,29 @@ class ReactViewGroupTest {
)
}

@Test
fun `requestFocusFromJS - focuses a focusable view in touch mode`() {
InstrumentationRegistry.getInstrumentation().setInTouchMode(true)
val rvg = attachedView().apply { isFocusable = true }
assertThat(rvg.isInTouchMode).isTrue()

rvg.requestFocusFromJS()

assertThat(rvg.isFocused).isTrue()
assertThat(rvg.isFocusableInTouchMode).isFalse()
}

@Test
fun `requestFocusFromJS - does not make a non-focusable view focusable`() {
InstrumentationRegistry.getInstrumentation().setInTouchMode(true)
val rvg = attachedView()

rvg.requestFocusFromJS()

assertThat(rvg.isFocused).isFalse()
assertThat(rvg.isFocusable).isFalse()
}

@Test
fun `View clipping - ensure allChildren properly resizes when adding views in sequence`() {
val rvg = ReactViewGroup(context)
Expand Down Expand Up @@ -470,6 +494,13 @@ class ReactViewGroupTest {
return view
}

private fun attachedView(): ReactViewGroup {
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
val view = ReactViewGroup(activity)
activity.setContentView(view)
return view
}

private fun hoverEvent(action: Int, position: Float): MotionEvent =
MotionEvent.obtain(0, 0, action, position, position, 0).apply {
source = InputDevice.SOURCE_MOUSE
Expand Down