Skip to content

Fix the modal's close button: VoiceOver name on iOS, Material placement on Android - #214

Open
wojt-janowski wants to merge 2 commits into
NativePHP:mainfrom
wojt-janowski:fix/modal-close-button
Open

wojt-janowski wants to merge 2 commits into
NativePHP:mainfrom
wojt-janowski:fix/modal-close-button

Conversation

@wojt-janowski

Copy link
Copy Markdown
Contributor

Two fixes to the modal's close button, one per commit, so either can be taken on its own.

Problem

  1. iOS: VoiceOver reads the close button as the modal's label. A11yLabelModifier puts the modal's a11y-label on the whole VStack. SwiftUI gives a plain container's accessibilityLabel to each child, so with a11y-label="Account details" the close button was announced as "Account details" instead of "Close".
  2. Android: the close button sits at the end 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 end is for the dialog's confirming action.

Fix

  1. NativeUIModalRenderer.swift: when there's a label, the stack becomes .accessibilityElement(children: .contain) before the label is applied. The label then names the modal and the close button keeps "Close". Without a label nothing changes.
  2. ModalRenderer.kt: the close row uses Arrangement.Start instead of Arrangement.End. Start follows the layout direction, so it's on the right in RTL. iOS keeps its trailing close button.

The Android status-bar icon fix this used to need is already in 0.10.0 (#194).

Test plan

  • tests/ModalRendererTest.php gains a case for each change, in the file's existing source-matching style. Each fails without its commit. Full suite: 504 passed; Pint clean.
  • iOS: a Firstlight Showcase build on an iPhone 17 Pro simulator (iOS 26.5) with the iOS change, read through the accessibility tree (axe describe-ui). Before: the close button's label was "Account details". After: Group 'Account details' containing Button 'Close', followed by the modal's text.
  • Android placement checked only in source; not rendered on a device or emulator. VoiceOver focus containment (.isModal) is unchanged in code but wasn't re-checked with VoiceOver running.

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 <wojt@clinically.com.au>
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 <wojt@clinically.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant