بنقرة واحدة
cross-platform-components
Overview of the Crystal cross-platform UI component system
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Overview of the Crystal cross-platform UI component system
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Run the asset_pipeline convention linter (`scripts/lint_conventions.cr`) — Crystal-side runner that enforces Phase 10 Family 1 naming rules across src/, samples/, and spec/. Use before commit, in CI, or when reviewing a PR.
Build cross-platform apps with UI::App + UI::Screen + UI::Controller + UI::ActionDispatcher + UI::FormState — route declarations, native action dispatch, Amber web integration, and the static-site web target.
The developer-facing guide to building Apple UI (iOS 26, iPadOS 26, macOS 26) with asset_pipeline's UI::View system. Backed by the Apple HIG corpus and validated by macOS + iOS screenshots. Answers "I want to show X — what component, what args, what HIG says."
Complete catalog of Android Jetpack Compose and Material Design 3 components. Covers M3 Expressive (2025), gesture system, graphics/drawing, navigation patterns, theming, and mapping guidance for Crystal cross-platform UI integration via JNI.
Full Apple Human Interface Guidelines corpus packaged offline as searchable markdown. Covers iOS, iPadOS, and macOS guidance for every HIG page, with cross-referenced links, downloaded illustrations, and a tag index. Use as the authoritative design reference when building native UI with asset_pipeline.
Comprehensive cross-platform UI component mapping matrix showing how every common UI pattern maps across Crystal UI::View, SwiftUI, UIKit, AppKit, Jetpack Compose, Android Views, and Web HTML/CSS. Implementation priority guide for expanding the asset_pipeline cross-platform component system.
| name | cross-platform-components |
| description | Overview of the Crystal cross-platform UI component system |
| version | 1.0 |
The cross-platform UI component system extends the asset_pipeline shard with native rendering for macOS (AppKit), iOS (UIKit), and Android (JNI/Views), alongside the existing web (HTML) output path. A single Crystal source tree defines a UI::View abstract class hierarchy that is rendered by platform-specific visitors selected at compile time via flag?(). Zero bytes of platform code leak across targets.
Core model: App code builds a tree of UI::View objects. A compile-time-selected PlatformRenderer (a PlatformVisitor subclass) walks the tree and produces native UI. The web renderer delegates to the existing Components::Elements system; native renderers call through ObjC or JNI bridges.
App Code (single Crystal source)
|
v
UI::View (abstract class hierarchy, pointer-sized virtual dispatch)
|
v
UI::PlatformVisitor (compile-time selected via flag?())
|
+-- Web::Renderer -> Components::Elements (existing HTML system)
+-- AppKit::Renderer -> NSView via ObjC bridge [flag?(:macos)]
+-- UIKit::Renderer -> UIView via ObjC bridge [flag?(:ios)]
+-- Android::Renderer -> Android Views via JNI bridge [flag?(:android)]
Layout is 100% delegated to each platform's native engine. There is no custom constraint solver or Flexbox implementation in Crystal. VStack maps to NSStackView / UIStackView / LinearLayout / flex-column; each platform handles its own geometry.
| View Type | Purpose |
|---|---|
UI::Label | Read-only text display with font, color, alignment, and line limit |
UI::Button | Tappable element with a text label and on_tap callback |
UI::VStack | Vertical stack layout arranging children top to bottom |
UI::HStack | Horizontal stack layout arranging children leading to trailing |
UI::ZStack | Z-axis overlay stack drawing children back to front |
UI::Image | Image display with content mode and optional tint |
UI::TextField | Editable single-line text input with change callback |
UI::ScrollView | Scrollable container for content exceeding visible bounds |
UI::Spacer | Flexible space that expands within a stack layout |
All view types are classes (not structs) because container views hold Array(View) children, creating recursive type relationships that Crystal structs cannot represent.
Use the cross-platform UI layer when:
Do NOT use this when:
Components::Elements directly)require "ui"
class CounterApp
@count = 0
def build_view : UI::View
stack = UI::VStack.new(spacing: 16.0, alignment: UI::Alignment::Center)
label = UI::Label.new("Count: #{@count}")
label.font = UI::Font.new(size: 24.0, weight: :bold)
stack << label
button = UI::Button.new("Increment") { @count += 1; nil }
stack << button
stack
end
end
This single definition renders as:
<div style="display:flex;flex-direction:column;gap:16px"> with <span> and <button> childrenNSStackView(vertical) containing NSTextField (non-editable) and NSButtonUIStackView(.vertical) containing UILabel and UIButtonLinearLayout(VERTICAL) containing TextView and MaterialButtonThe platform renderer is selected at compile time with zero runtime branching:
{% if flag?(:macos) %}
require "./renderers/appkit_renderer"
alias PlatformRenderer = UI::AppKit::Renderer
{% elsif flag?(:ios) %}
require "./renderers/uikit_renderer"
alias PlatformRenderer = UI::UIKit::Renderer
{% elsif flag?(:android) %}
require "./renderers/android_renderer"
alias PlatformRenderer = UI::Android::Renderer
{% else %}
require "./renderers/web_renderer"
alias PlatformRenderer = UI::Web::Renderer
{% end %}
The Crystal compiler eliminates all code for non-selected platforms. A macOS binary contains zero Android code, and vice versa.
| File | Purpose |
|---|---|
src/ui/view.cr | UI::View abstract class, Color, Font, EdgeInsets, enums |
src/ui/views/*.cr | All 9 concrete view types |
src/ui/platform_visitor.cr | UI::PlatformVisitor abstract class with 9 visit methods |
src/ui.cr | Top-level require that pulls in the full UI module |