Repository navigation
fix(View): do not flatten a view that is a live region - #59335
faciledictu wants to merge 1 commit into
Conversation
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D126905304. |
|
This pull request was successfully merged by @faciledictu in 5e13324 When will my fix make it into a release? | How to file a pick request? |
|
A correction to the summary above. I wrote that a live region needs a view of its own "unlike a hint or a label", because those are only announced on an On the same Samsung SM-A276B (Android 16, TalkBack 16.2) and React Native 0.88.0, a <View accessibilityLabel="Cart L1">
<Text>3 items L1</Text>
</View>
<View accessibilityLabel="Cart L2" collapsable={false}>
<Text>3 items L2 (control)</Text>
</View>TalkBack reads L2 as "Cart L2"; L1 is flattened and only "3 items L1" is read. So the |
Summary: Fixes react#59329. Related: react#59330 (`aria-live` on `Text`). A `View` with `aria-live` or `accessibilityLiveRegion` and no style is flattened by Fabric: `ViewShadowNode::initialize` keeps a host view for `accessibilityViewIsModal`, `accessibilityElementsHidden` and `importantForAccessibility`, but not for `accessibilityLiveRegion`. The live region never reaches the native tree, so TalkBack never announces changes to its children. The only workaround is `collapsable={false}`, which is not documented for live regions. This adds `accessibilityLiveRegion != None` to the conditions that form a stacking context, next to `accessibilityViewIsModal`. The prop only has an effect on Android; I put it in the shared check so it is covered by Fantom and because it is set only on views meant to be announced, but it could move to the Android `HostPlatformViewTraitsInitializer` instead if you prefer. This inverts the existing `does not unflatten view` test for `accessibilityLiveRegion`: unlike a hint or a label, a live region is announced without the view being `accessible`, so it needs a view of its own. ## Changelog: [ANDROID] [FIXED] - A `View` with `aria-live` or `accessibilityLiveRegion` is no longer flattened, so the live region is announced Pull Request resolved: react#59335 Test Plan: Added a Fantom test: `<View aria-live="polite" />` without `collapsable` or `accessible` is rendered as a host view with `accessibilityLiveRegion="polite"` (before the change it was flattened and the output was `null`). The existing `accessibilityLiveRegion` test `does not unflatten view` asserted the old behavior, so it is now `unflattens view` and expects the host view. On a device (Samsung SM-A276B, Android 16, TalkBack on) with the reproducer from react#59329 and React Native 0.88.0 built from source with this change: A, B and C are announced. Without the change, only B and C are announced. Reviewed By: christophpurrer Differential Revision: D126905304 Pulled By: javache fbshipit-source-id: 33cf5f191b20ce9253e669c95b8d95970a86517b
…r uses ## Summary: Fixes #59816. `ViewShadowNode::initialize` keeps a host view for only a few accessibility props (`accessible`, `accessibilityViewIsModal`, `accessibilityLiveRegion` and three more). iOS and Android also read several others from a view that is not an accessibility element, and they are lost when the view is flattened: - `accessibilityLabel`: TalkBack reads it from the container; an accessible ancestor builds its label from its subviews. - `accessibilityRole` / `role` and `accessibilityState`: the TabBar trait on iOS; heading, checkable and the state on Android. - `accessibilityActions`, `onAccessibilityEscape`, `onAccessibilityMagicTap`: iOS passes them to the elements inside or sends them up the hierarchy. - `accessibilityShowsLargeContentViewer`, `accessibilityIgnoresInvertColors`: they apply to the subviews on iOS. This change keeps the view when any of them is set, as #59335 did for `accessibilityLiveRegion`. The old architecture kept these views too. Left out on purpose: `accessibilityHint`, `accessibilityLanguage` and `accessibilityValue`, which are not read from a container, and `aria-busy` / `aria-checked="mixed"`: on Android they go into `contentDescription` and replace the children's text (a separate bug), so a kept view would be read as "busy". ## Changelog: [GENERAL] [FIXED] - A `View` with `accessibilityLabel`, `role`, `accessibilityState`, `accessibilityActions`, `onAccessibilityEscape` or another accessibility prop read from a container is no longer flattened ## Test Plan: - Fantom (`View-itest.js`): the `does not unflatten view` tests for `accessibilityLabel`, `accessibilityRole` and `accessibilityActions` asserted the bug and are now `unflattens view` (the `accessibilityActions` one also checked the wrong prop). Added: `role` and `aria-checked` unflatten, `aria-busy` and `aria-checked="mixed"` do not. The iOS-only props are not in the view config Fantom uses. The rest of the suite passes, except 9 `LogBoxInspector*` snapshot tests that fail the same way on `main` (93019c4). - On devices, with https://github.com/faciledictu/rn-a11y-flattening-repro and 0.88.0 built from source with this change backported, each flattened View now matches its `collapsable={false}` control (the results without the change are in #59816): - Android, the accessibility nodes on a device: sections 1, 2, 3, 6, 7, 8 and 13. - iOS simulator, Accessibility Inspector: sections 2, 3, 4, 5, 6 and 10 (the label "Close dialog P1" instead of "× P1", the Archive action, the Large Content Viewer, Smart Invert). - iPhone, VoiceOver: the tab is read as "Tab K1, tab, 1 of 2", and escape runs its own wrapper's handler, not the other dialog's. Differential Revision: D132245661 Pull Request resolved: #59817
Summary:
Fixes #59329. Related: #59330 (
aria-liveonText).A
Viewwitharia-liveoraccessibilityLiveRegionand no style isflattened by Fabric:
ViewShadowNode::initializekeeps a host view foraccessibilityViewIsModal,accessibilityElementsHiddenandimportantForAccessibility, but not foraccessibilityLiveRegion. The liveregion never reaches the native tree, so TalkBack never announces changes to
its children. The only workaround is
collapsable={false}, which is notdocumented for live regions.
This adds
accessibilityLiveRegion != Noneto the conditions that form astacking context, next to
accessibilityViewIsModal. The prop only has aneffect on Android; I put it in the shared check so it is covered by Fantom and
because it is set only on views meant to be announced, but it could move to
the Android
HostPlatformViewTraitsInitializerinstead if you prefer.This inverts the existing
does not unflatten viewtest foraccessibilityLiveRegion: unlike a hint or a label, a live region is announcedwithout the view being
accessible, so it needs a view of its own.Changelog:
[ANDROID] [FIXED] - A
Viewwitharia-liveoraccessibilityLiveRegionis no longer flattened, so the live region is announcedTest Plan:
Added a Fantom test:
<View aria-live="polite" />withoutcollapsableoraccessibleis rendered as a host view withaccessibilityLiveRegion="polite"(before the change it was flattened and the output was
null). The existingaccessibilityLiveRegiontestdoes not unflatten viewasserted the oldbehavior, so it is now
unflattens viewand expects the host view.On a device (Samsung SM-A276B, Android 16, TalkBack on) with the reproducer
from #59329 and React Native 0.88.0 built from source with this change:
A, B and C are announced. Without the change, only B and C are announced.