Skip to content

Return no next view when a ScrollView's content view is gone - #59075

Draft
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-focus-search-missing-content-view
Draft

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:fix/android-focus-search-missing-content-view

Conversation

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

Summary:

ReactScrollViewHelper.findNextFocusableView reads host.getChildAt(0).id without checking for the child, so a focus search that reaches a scroll view whose content view has already been removed throws from ReactScrollView.focusSearch:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getId()' on a null object reference
  at com.facebook.react.views.scroll.ReactScrollViewHelper.findNextFocusableView
  at com.facebook.react.views.scroll.ReactScrollView.focusSearch

#53046 reports it while a screen with a focused TextInput in a ScrollView navigates back; it was closed as stale, and main still dereferences the child. The search now returns null when there is no content view, so focusSearch keeps the platform's answer.

Changelog:

[ANDROID] [FIXED] - Crash in a ScrollView's keyboard focus search after its content view has been removed

Test Plan:

  • New Robolectric test ReactScrollViewHelperFocusSearchTest: a vertical and a horizontal scroll view with no content view, the Fabric lookup returning a next focusable. On main both fail with the NullPointerException above, thrown at the getChildAt(0).id read; with this change both return null.
  • ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.views.scroll.*" -PenableWarningsAsErrors=true passes, and ktfmt is clean on both files.

findNextFocusableView read host.getChildAt(0).id without checking for
the child, so a focus search on a scroll view whose content view had
already been removed threw a NullPointerException, as react#53046 reports
for a screen navigating back with a focused TextInput. It now returns
null, which leaves the platform's own answer in place.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant