From a04b23b5a19260b5af3b71d9e15fc3aadcfae6fe Mon Sep 17 00:00:00 2001 From: EnesKartal Date: Mon, 23 Nov 2026 23:36:43 +0300 Subject: [PATCH] fix(Dialog): announce accessible name on iOS VoiceOver when opening --- src/components/Modal.tsx | 20 ++++++++++++++------ src/components/__tests__/Dialog.test.tsx | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx index fa0c7eea6c..1fdbe51161 100644 --- a/src/components/Modal.tsx +++ b/src/components/Modal.tsx @@ -1,5 +1,11 @@ import * as React from 'react'; -import { Platform, StyleSheet, Pressable, View } from 'react-native'; +import { + AccessibilityInfo, + Platform, + Pressable, + StyleSheet, + View, +} from 'react-native'; import type { StyleProp, ViewStyle } from 'react-native'; import Animated, { @@ -263,13 +269,15 @@ function Modal({ // Transparent views are not in the accessibility tree, so focus has to // wait for the fade to finish. - const timeout = setTimeout( - focusInitialTarget, - getDuration(DEFAULT_DURATION) - ); + const timeout = setTimeout(() => { + focusInitialTarget(); + if (Platform.OS === 'ios' && ariaLabel) { + AccessibilityInfo.announceForAccessibility(ariaLabel); + } + }, getDuration(DEFAULT_DURATION)); return () => clearTimeout(timeout); - }, [animatedVisible, focusInitialTarget, getDuration]); + }, [animatedVisible, ariaLabel, focusInitialTarget, getDuration]); const transitionTimingFunction = cubicBezier(1 / 3, 1, 2 / 3, 1); diff --git a/src/components/__tests__/Dialog.test.tsx b/src/components/__tests__/Dialog.test.tsx index 92336dfafb..5447e3bbd8 100644 --- a/src/components/__tests__/Dialog.test.tsx +++ b/src/components/__tests__/Dialog.test.tsx @@ -1,5 +1,6 @@ import type { ComponentProps } from 'react'; import { + AccessibilityInfo, Text, StyleSheet, Platform, @@ -418,6 +419,28 @@ describe('Dialog', () => { expect(screen.getByLabelText('Alert')).toHaveProp('role', 'dialog'); }); + it('announces the dialog name on iOS when opening', async () => { + jest.useFakeTimers(); + jest.replaceProperty(Platform, 'OS', 'ios'); + const announceSpy = jest + .spyOn(AccessibilityInfo, 'announceForAccessibility') + .mockImplementation(() => {}); + + await render( + + + + ); + + await act(() => { + jest.runAllTimers(); + }); + + expect(announceSpy).toHaveBeenCalledWith('Alert'); + announceSpy.mockRestore(); + jest.useRealTimers(); + }); + it('should render a content', async () => { await render(