Skip to content

fix(iOS): reset accessibilityViewIsModal on view recycle to avoid trapping VoiceOver#57196

Open
doracawl wants to merge 2 commits into
react:mainfrom
doracawl:fix-accessibilityViewIsModal-recycle
Open

fix(iOS): reset accessibilityViewIsModal on view recycle to avoid trapping VoiceOver#57196
doracawl wants to merge 2 commits into
react:mainfrom
doracawl:fix-accessibilityViewIsModal-recycle

Conversation

@doracawl

@doracawl doracawl commented Jun 13, 2026

Copy link
Copy Markdown

Summary

RCTViewComponentView applies accessibilityViewIsModal in updateProps only when the prop changes:

// `accessibilityViewIsModal`
if (oldViewProps.accessibilityViewIsModal != newViewProps.accessibilityViewIsModal) {
  self.accessibilityElement.accessibilityViewIsModal = newViewProps.accessibilityViewIsModal;
}

…but prepareForRecycle never resets it. So when a view that had aria-modal / accessibilityViewIsModal is recycled and later reused for a different view that does not set the prop, the diff is NO (recycled default) == NO (new) and updateProps skips it — the stale accessibilityViewIsModal = YES leaks onto the recycled view.

A leftover modal view makes UIKit treat its subtree as the only accessible content, so VoiceOver and UI automation see an empty accessibility tree for the rest of the window until an unrelated layout pass recovers it.

This is easy to hit with transparent modals (e.g. a react-native-screens transparentModal) on iOS: open a modal → close it → reopen it. The recycled content view keeps the stale flag and competes with the modal's own transition view, collapsing the whole window's accessibility tree. It is intermittent because it depends on which pooled view instance is reused.

Changelog:

[iOS] [Fixed] - Reset accessibilityViewIsModal in prepareForRecycle so a stale modal flag no longer leaks onto recycled views and traps VoiceOver

Test Plan

Repro (iOS, Fabric):

  1. Render a <View aria-modal> (for example the content of a transparent modal), then unmount it so its underlying RCTViewComponentView returns to the recycle pool.
  2. Mount other content that reuses the recycled view without aria-modal.
  • Before: the reused view still reports accessibilityViewIsModal == YES; VoiceOver / Accessibility Inspector / a maestro hierarchy dump show a collapsed (near-empty) accessibility tree for the window.
  • After: the reused view reports accessibilityViewIsModal == NO; the accessibility tree is intact.

Verified on an iOS 26 simulator with a transparent-modal open → close → reopen cycle: UI-automation flows that read the accessibility tree go from intermittently failing to passing every run.

@meta-cla

meta-cla Bot commented Jun 13, 2026

Copy link
Copy Markdown

Hi @doracawl!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jun 13, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Jun 13, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 13, 2026

@tijuas16 tijuas16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trabajo realizado

@javache

javache commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Can we make this more complete and revert the defaults for the other accessibilityElement props too?

doracawl added a commit to doracawl/react-native that referenced this pull request Jun 25, 2026
Per @javache review feedback on react#57196: extend prepareForRecycle to
clear all accessibilityElement-side state that leaks across recycled
views, not just accessibilityViewIsModal. Defaults sourced from
AccessibilityProps.h; UIKit-side resets cover the props that
updateProps writes via direct UIKit setters.

Note: accessibilityRespondsToUserInteraction's C++ default is true,
so the reset value is YES (not NO).

Skipped: accessibilityActions / accessibilityLabelledBy /
accessibilityLiveRegion have no direct UIKit-side state to reset.
@doracawl

doracawl commented Jun 25, 2026

Copy link
Copy Markdown
Author

Thanks for the review @javache — pushed c4ab261 to extend prepareForRecycle to clear accessibility state set via accessibilityElement (label / language / hint / value / viewIsModal / elementsHidden / respondsToUserInteraction / identifier), plus a few self-only props (ignoresInvertColors, large content viewer, accessibilityOrder, accessibilityState bits).

Intentionally skipped isAccessibilityElement and accessibilityTraits — for RCTTextComponentView / RCTImageComponentView, accessibilityElement resolves to an inner UILabel / UIImageView whose native defaults (YES / StaticText|Image) would be regressed by a blanket reset to NO / None. Per-subclass reset is a separate follow-up. accessibilityState is cleared via the (.NotEnabled | .Selected) trait bit mask the setter writes on self.accessibilityTraits, which is safe across all subclasses. Full rationale lives in the commit message.

When a Fabric ComponentView is recycled, _props resets to the
AccessibilityProps default-constructed values. updateProps writes
most accessibility properties only when (oldProps != newProps),
so any UIKit-side state previously set stays stale across recycle
unless cleared in prepareForRecycle. The most visible failure is
`accessibilityViewIsModal` / `accessibilityElementsHidden` trapping
VoiceOver against a now-unrelated subtree.

Reset only the properties whose UIKit default does NOT depend on
the underlying view subclass. `isAccessibilityElement` and
`accessibilityTraits` are intentionally skipped: UIControl /
UILabel / UIImageView each start with different defaults from
UIView, and for RCTText/Image ComponentView `accessibilityElement`
resolves to an inner UILabel / UIImageView whose natural a11y
behavior would be clobbered by a blanket reset. Per-subclass
reset is left as a follow-up.

`accessibilityState` is cleared via the (.NotEnabled | .Selected)
trait bit mask the setter writes on self.accessibilityTraits —
safe across all subclasses.

Addresses review feedback on react#57196.
@doracawl doracawl force-pushed the fix-accessibilityViewIsModal-recycle branch from d4a788c to c4ab261 Compare June 25, 2026 14:04
@meta-codesync

meta-codesync Bot commented Jun 26, 2026

Copy link
Copy Markdown

@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D109810097.

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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants