Overview
Compose SwiftUI lets you write SwiftUI screens in Kotlin. It uses the Compose runtime, not Compose UI: your composables build a tree of SwiftUI views, and the app renders them with Apple's SwiftUI. Compose HTML does the same thing for the browser DOM.
Your Kotlin ViewModels, StateFlows and remember state work unchanged. You only rewrite the UI layer.
fun counterScreen() = composeSwiftUI {
val vm = viewModel { CounterViewModel() }
val count by vm.count.collectAsState()
NavigationStack {
VStack(spacing = 16.0, modifier = Modifier.navigationTitle("Counter")) {
Image(systemName = SFSymbol.swift, modifier = Modifier.font(Font.largeTitle).foregroundStyle(Color.orange))
Text("Count: $count", modifier = Modifier.font(Font.title))
Button("Increment", action = vm::increment)
}
}
}
ComposeView { CounterScreenKt.counterScreen() }Topics
Text and imagesText, Label, Image, LinkControlsButton, Toggle, Slider, StepperText inputTextField, SecureField, TextEditorLayout containersVStack, HStack, ZStack, LazyVStackLists and navigationList, Section, Form, ScrollViewLayout modifierspadding, frame, offset, fixedSizeAppearance modifiersfont, foregroundStyle, background, overlayText modifierslineLimit, multilineTextAlignmentInteraction and lifecycleonTapGesture, onAppear, onDisappear, taskNavigation and presentationnavigationTitle, toolbar, sheet, alertAnimationanimation, transitionStylesbuttonStyle, listStyleValuesColor, FontAccessibilityaccessibilityLabel