Skip to content

Commit 5e13324

Browse files
faciledictumeta-codesync[bot]
authored andcommitted
fix(View): do not flatten a view that is a live region (#59335)
Summary: Fixes #59329. Related: #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: #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 #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
1 parent 0e041dd commit 5e13324

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎packages/react-native/Libraries/Components/View/__tests__/View-itest.js‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ describe('<View>', () => {
601601
).toEqual(<rn-view accessibilityLiveRegion="polite" />);
602602
});
603603

604-
it('does not unflatten view', () => {
604+
it('unflattens view', () => {
605605
const root = Fantom.createRoot();
606606

607607
Fantom.runTask(() => {
@@ -612,7 +612,7 @@ describe('<View>', () => {
612612
root
613613
.getRenderedOutput({props: ['accessibilityLiveRegion']})
614614
.toJSX(),
615-
).toEqual(null);
615+
).toEqual(<rn-view accessibilityLiveRegion="polite" />);
616616
});
617617
});
618618

@@ -841,6 +841,20 @@ describe('<View>', () => {
841841
.toJSX(),
842842
).toEqual(<rn-view />);
843843
});
844+
845+
it('keeps the view from being flattened', () => {
846+
const root = Fantom.createRoot();
847+
848+
Fantom.runTask(() => {
849+
root.render(<View aria-live="polite" />);
850+
});
851+
852+
expect(
853+
root
854+
.getRenderedOutput({props: ['accessibilityLiveRegion']})
855+
.toJSX(),
856+
).toEqual(<rn-view accessibilityLiveRegion="polite" />);
857+
});
844858
});
845859

846860
describe('aria-busy', () => {

‎packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void ViewShadowNode::initialize() noexcept {
5353
isColorMeaningful(viewProps.shadowColor) ||
5454
viewProps.accessibilityElementsHidden ||
5555
viewProps.accessibilityViewIsModal ||
56+
viewProps.accessibilityLiveRegion != AccessibilityLiveRegion::None ||
5657
viewProps.importantForAccessibility != ImportantForAccessibility::Auto ||
5758
viewProps.removeClippedSubviews || viewProps.cursor != Cursor::Auto ||
5859
viewProps.onSafeAreaInsetsChange || !viewProps.filter.empty() ||

0 commit comments

Comments
 (0)