Kotlin Multiplatform, from the compiler up · Puzzle 9 · 10 of 10

One canvas on iOS

On iOS, your Compose screen doesn't become UIKit buttons and labels. It's drawn. Here's what UIKit sees, and why VoiceOver and native controls need a bridge.

The problem

Puzzle 8 said the platform layer is rewritten per target. On iOS, does your Column with a Button turn into a UIStackView with a UIButton? If it doesn't, how does VoiceOver know there's a button to read out?

See it

A UIKit app hosts one ComposeUIViewController; Compose draws the button and list with Skia; UIKit sees one view; semantics from Material components are mapped into the accessibility tree; a native map is placed in with UIKitView ComposeUIViewController Buttondrawn by Skia UIKit sees: one view accessibility treebutton "Pay" real MKMapViewUIKitView
  1. Your Swift code hosts the whole Compose screen as one view controller: ComposeUIViewController.

    Step 1 of 4
  2. Compose draws the button and the list itself with Skia. UIKit sees one view; it doesn't know there's a button. Predict: how does VoiceOver find it?

    Step 2 of 4
  3. Compose maps its semantics into iOS's accessibility tree: a Material button arrives there as a button.

    Step 3 of 4
  4. Something Skia can't draw, like a real map, goes in as a real UIKit view through UIKitView.

    Step 4 of 4

The building block

It doesn't turn into UIKit buttons and labels. Your Swift code hosts the whole Compose screen as one view controller, returned by ComposeUIViewController { App() }. Inside it, Compose draws every pixel itself with Skia, a graphics library for shapes and text, which Kotlin reaches through Skiko ("Skia for Kotlin").

So UIKit sees one view. It doesn't know there's a button at the top or a list below. That has two consequences.

First, accessibility. VoiceOver reads iOS's accessibility tree: the list of on-screen elements with their labels and roles. Compose already knows what each element is, from the semantics that Material components attach, so Compose Multiplatform maps that data into native accessibility objects. A Material Button arrives in the tree as a button. A shape you drew yourself, with no semantics, is invisible to VoiceOver, unless you give it some, for example with Modifier.semantics { contentDescription = "Pay" }, or make it clickable.

Second, native controls. A map, a web view or a video player is a UIKit view that Skia can't draw. UIKitView puts a real one into your Compose layout, and Compose sizes and positions it like any other composable.

And Compose doesn't have to own the whole app: a UIKit or SwiftUI app can show Compose for just one screen, one view controller among its own.

The analogy

A painted mural instead of a shop window full of real objects. Passers-by see the same scene, but a blind visitor needs a guide who knows what each painted thing is (the accessibility tree), and anything that must really open, like a door, is a real door set into the wall (UIKitView).

Check yourself

Your Compose screen on iOS has a Column with a Button. What does UIKit see?

Right. One view, drawn by Compose.

Not quite. UIKit still runs the app; Compose lives inside one of its screens.

Not quite. Compose doesn't create UIKit objects for composables; it draws them itself.

You draw a custom icon button yourself, as plain shapes with no semantics. What does VoiceOver read?

Not quite. UIKit sees one view; what's in the tree comes from Compose's semantics.

Right. No semantics, nothing to read.

Not quite. Skia only draws pixels; it doesn't tell iOS what they mean.

What's the difference between ComposeUIViewController and UIKitView?

Not quite. UIKitView goes the other way: a native view inside Compose.

Right. Opposite directions.

Not quite. That's the two swapped.

Sources

  • Skiko README ("Skiko (short for Skia for Kotlin) is the graphical library exposing significant part of Skia library APIs to Kotlin, along with the gluing code for rendering context"; supported platforms include "Kotlin/Native on iOS")
  • Kotlin docs: Support for iOS accessibility features ("semantics data produced by Compose APIs is now mapped to native objects and properties that are consumed by iOS Accessibility Services. For most interfaces built with Material widgets, this should happen automatically.")
  • Kotlin docs: Integration with the UIKit framework ("To use UIKit elements inside Compose Multiplatform, add the UIKit elements that you want to use to a UIKitView")

What you now know

On iOS, Compose Multiplatform draws your whole UI itself with Skia, through Skiko, inside one hosted view: ComposeUIViewController. UIKit sees one view, not your buttons. So Compose maps its own semantics into iOS's accessibility tree for VoiceOver, and a native control such as a map goes in through UIKitView.

That's everything published so far

You've reached the last puzzle of Kotlin Multiplatform, from the compiler up. Next: Module 3: Compose Multiplatform in practice, about touch, scrolling and text input on iOS; accessibility through VoiceOver; interop with SwiftUI and UIKit in both directions; resources and navigation.

New puzzles are announced on LinkedIn and in the learning log feed.

All courses →