Skip to content

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

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

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

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 14, 2026 •

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 the scroll view's 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, where the search runs from TextView.onCreateInputConnection as the input method starts on that field. The search now returns null when there is no content view, so focusSearch keeps the platform's answer.

Changelog:

[ANDROID] [FIXED] - Fix crash in a ScrollView's 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.
  • The test passes under -PenableWarningsAsErrors=true, and ktfmt is clean on both files.

@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
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/android-focus-search-missing-content-view branch from 3d3cdc5 to abe722d Compare November 11, 2026 16:59
@steadev

steadev commented Dec 3, 2026

Copy link
Copy Markdown

Adding some production data in support of this fix.

This is currently our top Android crash on RN 0.80.2 (New Architecture): 55 crashes affecting 47 users over the last 30 days, out of ~2.8k active users. The stack trace is identical:

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 (ReactScrollViewHelper.kt:500)
  at com.facebook.react.views.scroll.ReactScrollView.focusSearch (ReactScrollView.java:369)
  ...
  at android.widget.TextView.onCreateInputConnection (TextView.java:9728)
  at com.facebook.react.views.textinput.ReactEditText.onCreateInputConnection (ReactEditText.kt:341)
  at android.view.inputmethod.InputMethodManager.startInputInner (InputMethodManager.java:2469)
  ...
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:4442)

In our breadcrumbs it almost always happens right as the user navigates away from a screen that has a focused TextInput inside a ScrollView — the same trigger as #53046. Seen on Android 12 through 17.

I also checked 0.88.1 and current main: both still read host.getChildAt(0).id without a null check, so upgrading alone doesn't avoid it. Since react-android ships prebuilt, apps can't easily patch this locally — getting this merged would really help.

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor Author

Until this lands, an app can carry the change with patch-package by building ReactAndroid from source, which replaces the prebuilt react-android: https://reactnative.dev/contributing/how-to-build-from-source. That is how I ship it now.

@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/android-focus-search-missing-content-view branch from abe722d to 7cf1acd Compare December 4, 2026 18:32
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
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.

Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/android-focus-search-missing-content-view branch from 7cf1acd to 7ffadce Compare December 4, 2026 18:46
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Visual regression

No visual differences at 7ffadcef115f.

ios: no capture

@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review December 4, 2026 19:42

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. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants