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/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..2632b29 100644 --- a/tests/ModalRendererTest.php +++ b/tests/ModalRendererTest.php @@ -36,3 +36,22 @@ ->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\) \}/'); +}); + +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/'); +});