This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
swift build- Build the UIComponent Swift packageswift test- Run all tests in the packageswift test --filter <TestName>- Run specific test- Open
Examples/UIComponentExample.xcodeprojin Xcode to run the example app
UIComponent is a declarative UI framework for UIKit with SwiftUI-like syntax and unidirectional data flow.
Modern approach: Render components on any UIView using:
view.componentEngine.component = VStack {
Text("Hello World!")
}
ComponentView and ComponentScrollView are deprecated. The componentEngine extension on UIView (Sources/UIComponent/Core/ComponentView/UIView+ComponentEngine.swift) provides:
- Lazy initialization with method swizzling
- Integration with
layoutSubviews,setBounds,sizeThatFits - Special UIScrollView handling for safe areas and content insets
- Component - Define UI structure with
layout(_:)method - RenderNode - Layout result with size, positions, children
- Visibility Test -
visibleChildren(in frame:)determines what to render - Renderable - Maps to actual UIViews in hierarchy
- ComponentEngine - Manages reload/render cycles with diff algorithm
- Layout Components:
VStack/HStack/ZStack(Sources/UIComponent/Components/Layout/Stack/) - FlexLayout: CSS Flexbox-like layouts (
Sources/UIComponent/Components/Layout/Flex/) - View Components:
Text,Image,ViewComponentfor custom UIViews - Modifiers: Chainable properties like
.size(),.backgroundColor(),.tappableView()
- Lazy Loading:
.lazy(width:height:)defers layout until needed - View Reuse: Explicit
.reuseKey()modifier for cell reuse (v5.0+) - Async Layout:
view.componentEngine.asyncLayout = truefor background layout - Visibility Testing: Only renders components within visible bounds
VStack {
Text("UIComponent Text")
SwiftUI.Text("SwiftUI Text").foregroundColor(.red)
SwiftUIComponent {
SwiftUI.VStack { /* SwiftUI content */ }
}.backgroundColor(.black)
}
UIComponent doesn't provide built-in state management. Recommended pattern:
class MyViewController: UIViewController {
var viewModel = MyViewModel() {
didSet { reloadComponent() }
}
func reloadComponent() {
view.componentEngine.component = VStack {
Text("Count: \(viewModel.count)")
}
}
}
- v2.0: Unified Component/ViewComponent, removed
.view()requirement - v4.0: Any UIView can render components via
componentEngine - v5.0: SwiftUI integration, explicit view reuse with
.reuseKey(), context value system