Skip to content
Flow-UILive
On this page

Accessibility in server driven SwiftUI

Native widgets inherit VoiceOver. The schema still has to send alt text, button traits, and type that scales.

Ayush MishraPublished 6 min read

Accessibility in server driven SwiftUI is native because the widget is a real SwiftUI view, and it is incomplete until the schema sends the labels the platform cannot invent. VoiceOver, Dynamic Type, and button traits come from UIKit and SwiftUI. Alt text, tap actions, and font sizes come from the JSON. Drop either half and the page looks fine to a sighted engineer with default type and fails for everyone else.

Hacker News threads on "What Is Server-Driven UI?" keep returning to the same objection: if this is a WebView, you gave up localisation, dark mode, and accessibility. Native SDUI is the reply. This post is the proof against Flow-UI's sources, not a scoreboard. See atoms for the fields, architecture for where they attach, and what native means for the view-debugger test.

What you inherit from the platform#

A WidgetView is a View. Scrolling is ScrollView physics. Focus, rotor, and the accessibility inspector see the same tree they see in a handwritten SwiftUI page. You do not ship a parallel a11y engine.

That inheritance is a floor. A Rectangle plus onTapGesture is invisible to VoiceOver: no trait, no action, no hint that the control does anything. Flow-UI's envelope layer exists so a backend-declared tap does not become that trap.

Envelope taps become buttons#

EnvelopeGestures on the widget row attaches onTapGesture and onLongPressGesture only when the backend sent those events. When a tap is present, the modifier also:

  • Combines children into one accessibility element
  • Adds the .isButton trait
  • Registers an accessibility action that dispatches "tap"
  • Names a "Long press" action when long_press is present

The trait is not a separate JSON key. It rides on the envelope actions object you already send for sighted users. If the widget is tappable with a finger, it is a button to VoiceOver. If it is not tappable, it stays passive. Do not add a fake tap so the row "feels clickable" in a screenshot; you will announce a control that does nothing useful.

Starter widgets that draw their own controls still have to label them. button_row uses FlowButton. stepper_row hides decorative chrome, labels the title, and exposes the count as an accessibility value. Copy that pattern in your product widgets. The envelope cannot see inside a custom body.

Images: alt or decorative#

ImageData.alt is optional on purpose. An image with no alt is treated as decorative and hidden from assistive technology. That is the right default for backdrops, scrims, and repeating merchandise photography that the adjacent title already names. It is the wrong default for an image that carries meaning the text does not repeat: a status glyph, a diagram, a photo that is the content.

json
{
  "url": "https://cdn.example/hero.jpg",
  "aspect_ratio": 1.6,
  "alt": "Navy running jacket, front zip, worn on a trail"
}

FlowImage maps a non-empty alt to an accessibility element with .isImage and that label. Empty or missing alt calls accessibilityHidden(true). CMS authors who leave alt blank are not getting a filename announced; they are getting silence. Train the CMS. Do not invent alt on the client from the URL.

Bare string shorthand { "image": "https://..." } has no alt. Use the object form for anything meaningful.

Type that scales#

Every font in the framework used to be .system(size:), a pinned point size. A page built that way ignored Dynamic Type entirely. Sizes now go through FlowFontScaling in DynamicTypeScaling.swift: the backend point size is mapped to the nearest built-in text style, then UIFontMetrics scales it. Views that render scaled text read @Environment(\.dynamicTypeSize) so SwiftUI re-evaluates when the setting changes.

ThemeDefaults.scalesFontsWithDynamicType defaults to true. Hosts that need pinned sizing, a tightly art-directed banner for instance, can turn it off on their theme. That is an explicit opt-out, not the default.

Icons go through scaledIcon so glyphs keep pace with the text they sit beside instead of staying stubbornly small.

macOS has no UIFontMetrics equivalent in this helper, so sizes stay as sent there. iOS is the surface this article is about.

AccessibleOrderWidget.swiftswift
import SwiftUI
import FlowRender
 
struct AccessibleOrderWidget: WidgetView {
    let content: OrderCardContent
    let context: WidgetContext
 
    var body: some View {
        VStack(alignment: .leading, spacing: 8) {
            FlowText(content.orderNumber)
            FlowImage(content.heroImage)
        }
    }
}

FlowText and FlowImage pick up theme, scaling, and alt. A raw Text(content.orderNumber.text).font(.system(size: 16)) opts out. The untitled registration is the same as every other widget:

swift
registry.register(AccessibleOrderWidget.self)

What the schema still has to send#

Native widgets do not invent copy. You still need:

FieldWhere it livesIf you omit it
ImageData.altImage atomsImage is decorative and hidden
Envelope actions.tapWidget envelopeNo button trait, no activation action
FontData.size or tokenText atomsFallback body font from ThemeDefaults
Button titleButtonDataThe control has nothing to announce
Dark hex or tokensColorDataContrast in dark appearance is guesswork

Localisation is a backend concern. Flow-UI does not translate. Send the string the user should hear. Dynamic Type scales the font; it does not shorten English.

Do not put essential instructions only in a background image. VoiceOver will skip it if alt is missing, and a large type user may never see the full bitmap.

Custom widgets are where teams regress#

The starter catalogue is eight worked examples. Your order_card is where accessibility usually dies: a HStack of unlabelled icons, a stepper drawn as two tappable Texts, a badge that is colour only.

Rules that match the package conventions:

  • Meaningful images take an alt.
  • Controls you build yourself get a label.
  • Backend font sizes go through the theme so they scale with Dynamic Type.
  • Do not apply layout chrome inside the view; the renderer already wraps the body.

If you wrap the whole widget in .accessibilityElement(children: .ignore) and forget a label, you have built a hole. Prefer .combine when the envelope already treats the row as one button.

Dark mode is part of the same story#

Colour contrast is accessibility. ColorData.dark_hex and ThemeProvider tokens are how the page stays readable when appearance flips, without a second payload. That is covered in theming server driven SwiftUI. A 4.5:1 ratio is your bar, not a Flow-UI feature. The framework only resolves what you sent.

WebViews can be accessible. They are a different product: web semantics, web focus, web type. Pick them for documents. Pick native widgets when the page should feel like the rest of the app. SDUI on iOS is native SwiftUI, not WebViews.

The Flow-UI mark: two nodes joined through a filled centre

Accessibility in server driven SwiftUI: inherit VoiceOver from the view tree, send alt, declare taps so they become buttons, and let backend sizes scale. The schema is the other half of native.

More on the blog.

Read the source

Flow-UI is MIT licensed. The schema, renderer and starter widgets live on GitHub.

GitHub

Get started with Flow-UI

Install the Swift package, register a widget, and render a page from JSON.

Get started