From 846fec0adb3c00b4abc99b317b37312269882327 Mon Sep 17 00:00:00 2001 From: Wojt Janowski Date: Sun, 15 Nov 2026 02:24:14 +0000 Subject: [PATCH 1/2] Keep the iOS modal's close button named Close for VoiceOver The modal applies its a11y-label to the whole stack, and SwiftUI gives a plain container's label to each of its children, so VoiceOver read the close button as the modal's label ("Account details") instead of "Close". The stack is now an accessibility element that contains its children, so the label names the modal and the close button keeps its own. Amp-Thread-ID: https://ampcode.com/threads/T-01a1dca0-8660-73ca-b541-c07f690843ea Co-authored-by: Wojt Janowski --- resources/ios/NativeUIModalRenderer.swift | 6 +++++- tests/ModalRendererTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/ios/NativeUIModalRenderer.swift b/resources/ios/NativeUIModalRenderer.swift index bd6fb0f..ff90624 100644 --- a/resources/ios/NativeUIModalRenderer.swift +++ b/resources/ios/NativeUIModalRenderer.swift @@ -66,6 +66,10 @@ private struct A11yLabelModifier: ViewModifier { let label: String func body(content: Content) -> some View { if label.isEmpty { content } - else { content.accessibilityLabel(label) } + // A label on a plain container is applied to each child, so the close + // button was read as the modal's label instead of "Close". Making the + // container an element that contains its children names the container + // and leaves the children's own labels alone. + else { content.accessibilityElement(children: .contain).accessibilityLabel(label) } } } diff --git a/tests/ModalRendererTest.php b/tests/ModalRendererTest.php index 9c7b5b7..820b4c0 100644 --- a/tests/ModalRendererTest.php +++ b/tests/ModalRendererTest.php @@ -36,3 +36,13 @@ ->not->toMatch('/onDismiss: \{/') ->toMatch('/Button\(action: fireDismiss\)/'); }); + +test('names the iOS modal without renaming its close button', function () { + $renderer = file_get_contents(dirname(__DIR__).'/resources/ios/NativeUIModalRenderer.swift'); + + expect($renderer) + ->toBeString() + ->toMatch('/\.accessibilityLabel\("Close"\)/') + ->toMatch('/content\.accessibilityElement\(children: \.contain\)\.accessibilityLabel\(label\)/') + ->not->toMatch('/else \{ content\.accessibilityLabel\(label\) \}/'); +}); From 494fdd66d007ebe52e378b8e9e5d3f2dc93c14b7 Mon Sep 17 00:00:00 2001 From: Wojt Janowski Date: Sun, 15 Nov 2026 02:24:43 +0000 Subject: [PATCH 2/2] Put the Android modal's close button at the start of its row Material 3 full-screen dialogs put the close icon at the start of the top bar, where a screen's navigation icon goes. The modal drew it at the end, which is where the dialog's confirming action belongs. Start follows the layout direction, so in right-to-left layouts it sits on the right. Amp-Thread-ID: https://ampcode.com/threads/T-01a1dca0-8660-73ca-b541-c07f690843ea Co-authored-by: Wojt Janowski --- resources/android/ModalRenderer.kt | 5 ++++- tests/ModalRendererTest.php | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/android/ModalRenderer.kt b/resources/android/ModalRenderer.kt index 6c82351..ad8f546 100644 --- a/resources/android/ModalRenderer.kt +++ b/resources/android/ModalRenderer.kt @@ -109,7 +109,10 @@ object ModalRenderer { .fillMaxWidth() .statusBarsPadding() .padding(8.dp), - horizontalArrangement = Arrangement.End, + // Material 3 full-screen dialogs put close at the start of + // the top bar, where the navigation icon goes; it follows + // the layout direction, so it moves to the right in RTL. + horizontalArrangement = Arrangement.Start, ) { IconButton(onClick = { showModal = false diff --git a/tests/ModalRendererTest.php b/tests/ModalRendererTest.php index 820b4c0..2632b29 100644 --- a/tests/ModalRendererTest.php +++ b/tests/ModalRendererTest.php @@ -46,3 +46,12 @@ ->toMatch('/content\.accessibilityElement\(children: \.contain\)\.accessibilityLabel\(label\)/') ->not->toMatch('/else \{ content\.accessibilityLabel\(label\) \}/'); }); + +test('puts the Android modal close button at the start of its row', function () { + $renderer = file_get_contents(dirname(__DIR__).'/resources/android/ModalRenderer.kt'); + + expect($renderer) + ->toBeString() + ->toMatch('/\.padding\(8\.dp\),\s*(\/\/[^\n]*\n\s*)*horizontalArrangement = Arrangement\.Start,/') + ->not->toMatch('/horizontalArrangement = Arrangement\.End/'); +});