StateUI — a Swift declarative UI layer for .NET MAUI

Hi everyone,

I've been working on StateUI:

https://github.com/idexus/StateUI

It started as an experiment — how far could Swift go as the application and UI language outside the Apple stack, without building yet another cross-platform widget toolkit? Swift does the declarative UI, the state and the reconciliation; .NET MAUI provides the controls and the platform layer on iOS, Android, Windows and Mac Catalyst.

A complete application - a window, two tabs, and the state that moves them:

enum Tab: Hashable, CaseIterable {
    case counter
    case list
}

struct GalleryApp: Application {
    func createWindow() -> Window { MainWindow() }
}

struct MainWindow: Window {
    @State private var tab: Tab = .counter

    var title: String? { "StateUI" }

    var content: Page {
        TabbedPage(Tab.allCases) { which in
            switch which {
            case .counter: CounterPage(tab: $tab)
            case .list:    ListPage()
            }
        }
        .selection($tab)
    }
}

struct CounterPage: ContentPage {
    @Binding var tab: Tab

    @State private var counter = 0

    var title: String? { "Counter" }

    var content: Element {
        VStack {
            Label("Count: \(counter)")
                .fontSize(20)
                .horizontalTextAlignment(.center)

            Button("Increment")
                .cornerRadius(8)
                .onClicked { counter += 1 }

            Button("Go to the list")
                .onClicked { tab = .list }
        }
        .spacing(20)
        .padding(24)
    }
}

struct ListPage: ContentPage {
    var title: String? { "List" }

    var content: Element {
        CollectionView(1...100) { number in
            Label("Row \(number)")
                .fontSize(16)
                .padding(16, 12)
        }
        .itemSize(44)
    }
}

Swift keeps the rendered tree, tracks which state each view read, and reconciles. What crosses to C# is a sparse binary patch — only what changed — and the MAUI side applies it to the native controls already on screen.

It is at 0.2.0 — every control MAUI 10 draws, a gallery app that exercises each one, and 660 Swift plus 512 C# tests. The API still moves between versions, and the 0. in front is meant literally.

I'm curious what people make of the broader idea: Swift as the declarative layer over an existing native UI runtime, rather than a new widget stack underneath it.


14 Likes

Small update — Linux works now. Same Swift tree on iOS, Android, macOS, Windows and Linux; on Linux it's real GTK4 widgets, through MAUI's (preview) GTK4 backend.

The gallery on Ubuntu 24.04, GTK4