Repository navigation
Reset accessibility state when recycling Android views - #59047
Closed
YevheniiKotyrlo wants to merge 4 commits into
Closed
YevheniiKotyrlo wants to merge 4 commits into
YevheniiKotyrlo wants to merge 4 commits into
Conversation
With view recycling on, prepareToRecycleView clears the accessibility tags a view's props wrote but not the state those props applied to the view itself. The next view built from it applies only the props it declares, so it announces the previous view's content description and role, reads as selected, keeps its live region and screen-reader focusability, and stays hidden from accessibility services when the previous view was. Reset that state to a new view's, clear the accessibility delegate on the view, and restore TextView's default importance in ReactTextView.recycleView.
Contributor
Author
With experimental_accessibilityOrder on, a recycled ReactViewGroup kept the order list its previous props set, and a recycled child kept the parent and focusability tags its former parent's order put on it, the parent tag holding on to that view. ReactViewGroup.initView clears the list and prepareToRecycleView clears both tags, as a new view has them.
YevheniiKotyrlo
marked this pull request as ready for review
October 14, 2026 09:10
javache
requested changes
Oct 14, 2026
A delegate keeps the actions it registered while building node info, so a view recycled from one that declared an activate action dispatched that action on TalkBack's click instead of performing the click. The case fails without prepareToRecycleView clearing the delegate.
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D125427268. |
YevheniiKotyrlo
marked this pull request as draft
October 16, 2026 09:44
…tions Clearing the whole delegate in prepareToRecycleView also removed the ReactScrollViewAccessibilityDelegate that ReactScrollView, ReactHorizontalScrollView and ReactNestedScrollView install in their constructors, which recycleView never installs again. The delegate now stays, and ReactAccessibilityDelegate.prepareToRecycle() clears the actions it cached from the previous props. accessibilityLabelledBy was only read in the call that set it, so it is a local there.
YevheniiKotyrlo
marked this pull request as ready for review
October 16, 2026 10:23
javache
approved these changes
Oct 16, 2026
Collaborator
|
This pull request was successfully merged by @YevheniiKotyrlo in 6f73542 When will my fix make it into a release? | How to file a pick request? |
4 of 11 tasks
usama-liaqat
pushed a commit
to usama-liaqat/react-native
that referenced
this pull request
Nov 14, 2026
Summary: With `enableViewRecycling` on, a recycled view keeps the accessibility state its previous props applied. `BaseViewManager.prepareToRecycleView` clears the accessibility tags, but not the content description, `importantForAccessibility`, the selected state, the live region, `screenReaderFocusable`, the `role` and collection tags, or the actions its accessibility delegate cached. The next view of that type is built from it and applies only the props it declares, so TalkBack announces a label and a role the view never had, the delegate sends TalkBack's click to an action only the previous props declared, and a view last used inside an `aria-hidden` subtree hides its new content from accessibility services. With `experimental_accessibilityOrder` on as well, a recycled `ReactViewGroup` keeps its previous order list, and a recycled child keeps the parent and focusability tags its former parent's order put on it. This resets that state in `prepareToRecycleView` to what a new view has, clears the order list in `ReactViewGroup.initView`, and restores `TextView`'s default importance in `ReactTextView.recycleView`. The delegate stays, since `ReactScrollView`, `ReactHorizontalScrollView` and `ReactNestedScrollView` install theirs in their constructors: a new `ReactAccessibilityDelegate.prepareToRecycle()` clears the actions it cached, and `accessibilityLabelledBy`, read only in the call that sets it, is a local there. It sits beside the `enabled` reset react#58799 added. ## Changelog: [ANDROID] [FIXED] - Recycled views no longer keep the accessibility state of their previous props Pull Request resolved: react#59047 Test Plan: New cases in `BaseViewManagerTest` and `ReactTextViewPropertyTest` recycle a view through `onDropViewInstance` and `createView` and compare it with a new one. Before the change six fail: content description `"Dismiss sheet"`, `role` tag `LIST`, a click dispatched to the previous props' `activate` action instead of performed, importance `4` where a new text view has `1`, the order list `["first"]`, and the former parent in `accessibility_order_parent`. Another case recycles each scroll view and checks that it keeps the `ReactScrollViewAccessibilityDelegate` its constructor installed. With the change, `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -PenableWarningsAsErrors=true` passes (727 tests) and the release sources compile with the same flag; the RNTester debug build and the rest of `build_android` were not run. RNTester with view recycling on, on an Android 16 emulator with TalkBack, [before and after](react#59047 (comment)): plain rows mounted after labelled rows were removed are read as a selected "Dismiss sheet" button without the change, and as their text with it. On a Galaxy S23 (Android 14) app with view recycling on, plain rows mounted after rows carrying `aria-label`, `role`, `aria-selected`, `aria-disabled` and `aria-hidden` were removed reported the removed rows' label as their content description before the change. Built from source with it, the same rows report no label, role, selected or disabled state, and their text is in the accessibility tree. Both device runs used the first revision of this change, which cleared the delegate on recycle instead of resetting it. Reviewed By: Abbondanzo Differential Revision: D125427268 Pulled By: javache fbshipit-source-id: 1dad635ef6f1e5cef351d355865edc567f7bce58
meta-codesync Bot
pushed a commit
that referenced
this pull request
Nov 23, 2026
## Summary: #58799 fixed the original Pressable tap-target reset on `main`. This follow-up keeps that reset in `ReactViewManager`. Applying it in every manager can re-enable a non-editable `TextInput` when accessibility disabled is cleared, because `ReactTextInputManager` does not derive from `ReactViewManager` and controls its enabled state through `editable`. `BaseViewManager` now has a protected instance hook, `resetDisabledFromAccessibilityState`, that does nothing by default. `ReactViewManager` overrides it to restore the enabled state that accessibility disabled took away, so its subclasses get the same behavior without a class check. `setViewState` clears the disabled tag itself, so view managers don't need to call super. Other managers keep the enabled state they control. Since this PR was opened, #59387 started sending the full `accessibilityState` with Props 2.0 and #59047 re-enables views on recycle, so the earlier C++ prop change and the `ReactViewGroup` change are no longer part of this PR. The JavaScript components are unchanged. ## Changelog: [ANDROID] [FIXED] - Preserve non-editable text inputs when accessibility disabled is cleared. ## Test plan: With the Android SDK, JDK 21, and Yarn v1 on the environment path: ```sh ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \ --tests com.facebook.react.uimanager.BaseViewManagerTest \ --tests com.facebook.react.views.textinput.ReactTextInputPropertyTest \ --tests com.facebook.react.views.view.ReactViewGroupTest \ -Preact.internal.useHermesStable=true --no-daemon --max-workers=2 \ -Dorg.gradle.jvmargs='-Xmx2g -XX:MaxMetaspaceSize=768m' --console=plain ``` All 82 tests pass. The non-editable `TextInput` test fails on `main` and passes with this change. A `ReactViewManager` subclass test checks that subclasses inherit the reset. The `ReactAndroid.api` lines were checked against the compiled classes with `javap`. No full Android build, emulator, or device test was run. Differential Revision: D133495913 Pull Request resolved: #58795
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary:
With
enableViewRecyclingon, a recycled view keeps the accessibility state its previous props applied.BaseViewManager.prepareToRecycleViewclears the accessibility tags, but not the content description,importantForAccessibility, the selected state, the live region,screenReaderFocusable, theroleand collection tags, or the actions its accessibility delegate cached. The next view of that type is built from it and applies only the props it declares, so TalkBack announces a label and a role the view never had, the delegate sends TalkBack's click to an action only the previous props declared, and a view last used inside anaria-hiddensubtree hides its new content from accessibility services. Withexperimental_accessibilityOrderon as well, a recycledReactViewGroupkeeps its previous order list, and a recycled child keeps the parent and focusability tags its former parent's order put on it.This resets that state in
prepareToRecycleViewto what a new view has, clears the order list inReactViewGroup.initView, and restoresTextView's default importance inReactTextView.recycleView. The delegate stays, sinceReactScrollView,ReactHorizontalScrollViewandReactNestedScrollViewinstall theirs in their constructors: a newReactAccessibilityDelegate.prepareToRecycle()clears the actions it cached, andaccessibilityLabelledBy, read only in the call that sets it, is a local there. It sits beside theenabledreset #58799 added.Changelog:
[ANDROID] [FIXED] - Recycled views no longer keep the accessibility state of their previous props
Test Plan:
New cases in
BaseViewManagerTestandReactTextViewPropertyTestrecycle a view throughonDropViewInstanceandcreateViewand compare it with a new one. Before the change six fail: content description"Dismiss sheet",roletagLIST, a click dispatched to the previous props'activateaction instead of performed, importance4where a new text view has1, the order list["first"], and the former parent inaccessibility_order_parent. Another case recycles each scroll view and checks that it keeps theReactScrollViewAccessibilityDelegateits constructor installed. With the change,./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -PenableWarningsAsErrors=truepasses (727 tests) and the release sources compile with the same flag; the RNTester debug build and the rest ofbuild_androidwere not run.RNTester with view recycling on, on an Android 16 emulator with TalkBack, before and after: plain rows mounted after labelled rows were removed are read as a selected "Dismiss sheet" button without the change, and as their text with it.
On a Galaxy S23 (Android 14) app with view recycling on, plain rows mounted after rows carrying
aria-label,role,aria-selected,aria-disabledandaria-hiddenwere removed reported the removed rows' label as their content description before the change. Built from source with it, the same rows report no label, role, selected or disabled state, and their text is in the accessibility tree.Both device runs used the first revision of this change, which cleared the delegate on recycle instead of resetting it.