Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion resources/android/ModalRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion resources/ios/NativeUIModalRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
19 changes: 19 additions & 0 deletions tests/ModalRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
});
Loading