Skip to content

fix: OverKeyboardView crash with a11y - #962

Merged
kirillzyusko merged 1 commit into
mainfrom
fix/over-keyboard-view-accessibility-crash
Jun 2, 2025
Merged

kirillzyusko merged 1 commit into
mainfrom
fix/over-keyboard-view-accessibility-crash

Conversation

@kirillzyusko

@kirillzyusko kirillzyusko commented Jun 1, 2025 •

Copy link
Copy Markdown
Owner

📜 Description

Fixed a crash when TalkBack is enabled on Android and you use OverKeyboardView.

💡 Motivation and Context

The problem comes from the fact that the system tries to traverse the view hierarchy, but overlay views are not part of the main view hierarchy.

OverKeyboardHostView pretends that the views you pass to it are its own children. From the platform’s point of view those views are not really descendants of OverKeyboardHostView — they live in a completely different window created with WindowManager.addView.

When the Android accessibility framework walks the view-tree it calls addChildrenForAccessibility(), iterates over getChildAt(i) and finally calls:

offsetRectBetweenParentAndChild(parent, child);

That helper checks that child is a true descendant of parent, and if it isn’t it throws the exception you see:

java.lang.IllegalArgumentException: parameter must be a descendant of this view

To solve this I decided to exclude OverKeyboardHostView from accessibility traversal, so that inner views handles accessibility on their own (this is how it should work).

Closes #961

📢 Changelog

Android

  • don't add OverKeyboardView container to an accessibility;

🤔 How Has This Been Tested?

Tested manually in Fabric example on Pixel 7 Pro API 35.

📸 Screenshots (if appropriate):

telegram-cloud-document-2-5323756428911999326.mp4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@github-actions

github-actions Bot commented Jun 1, 2025

Copy link
Copy Markdown
Contributor

📊 Package size report

Current size Target Size Difference
197665 bytes 197487 bytes 178 bytes 📈

@kirillzyusko kirillzyusko self-assigned this Jun 1, 2025
@kirillzyusko kirillzyusko added 🎯 crash Library triggers a crash of the app OverKeyboardView Anything related to OverKeyboardView labels Jun 1, 2025
@kirillzyusko kirillzyusko changed the title fix: OverKeyboardView crash with a11y fix: OverKeyboardView crash with a11y Jun 2, 2025
@kirillzyusko
kirillzyusko merged commit 76226df into main Jun 2, 2025
@kirillzyusko
kirillzyusko deleted the fix/over-keyboard-view-accessibility-crash branch June 2, 2025 20:55
meta-codesync Bot pushed a commit to react/react-native that referenced this pull request Apr 2, 2026
Summary:
Guard `ReactViewGroup.addChildrenForAccessibility` against transient non-descendant races during accessibility traversal on Android.

This replaces direct `super.addChildrenForAccessibility(...)` calls with a small wrapper that:
- catches `IllegalArgumentException`
- only swallows the specific "descendant of this view" case
- rethrows all other `IllegalArgumentException`s

## Why
There are recurring crashes with stack traces ending in:
`ViewGroup.offsetRectBetweenParentAndChild` -> `offsetDescendantRectToMyCoords` -> `addChildrenForAccessibility` -> `IllegalArgumentException: parameter must be a descendant of this view`.

This can happen when accessibility is traversing children while views are being re-parented/removed.

Related reports:
- #32649
- #38925
- #7377
- kirillzyusko/react-native-keyboard-controller#961
- kirillzyusko/react-native-keyboard-controller#962
- dotnet/maui#32927

There is also precedent in RN for handling this class of non-descendant race defensively:
- #55273

## Scope
This is intentionally minimal and localized to accessibility child collection in `ReactViewGroup`. Behavior is unchanged in the non-racy path.

## Changelog:
[Android] [Fixed] - Guard `ReactViewGroup.addChildrenForAccessibility` against transient non-descendant accessibility traversal crashes.

Pull Request resolved: #56182

Test Plan: Validated in a downstream RN Android app on Android 16 with repeated sheet/modal open-close stress and active accessibility hierarchy traversal; crash reproduces before patch and no longer reproduces with this guard.

Reviewed By: jorge-cab

Differential Revision: D97861147

Pulled By: Abbondanzo

fbshipit-source-id: 15e624a94d5acd99777a7426787b52d8e85cdf8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎯 crash Library triggers a crash of the app OverKeyboardView Anything related to OverKeyboardView

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OverKeyboardView make the default expo template crash

1 participant