build-native-mobile-ui
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Builds native mobile UI in SwiftUI (iOS) and Jetpack Compose (Android) — declarative layout (List/LazyVStack vs Scaffold/LazyColumn), unidirectional state with hoisting (@Observable vs ViewModel/StateFlow), typed navigation stacks with deep links, adaptive sizing (size classes/WindowSizeClass), light/dark theming via semantic tokens, lifecycle-correct side effects, recomposition control, and VoiceOver/TalkBack accessibility.
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-office-docsSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- compose-local-dev-stackSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- contract-testingSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-ci-pipeline-failureSkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- design-token-systemSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 73
Default: screen state lives in @Observable (iOS 17+) / ViewModel.
- Very specific: line 99
Safe area / insets: never hardcode status-bar or notch padding.
- Very specific: line 100
Dynamic Type / font scale: use semantic styles (.font(.body) / MaterialTheme.typography.bodyLarge), not fixed pt/sp.
- Distinctive: line 112
Never gate logic on the literal color.
- Distinctive: line 114
Accessibility is a build requirement, not a pass: Every interactive element needs a label + role.
- Distinctive: line 117
Don't override the framework focus order unless reading order is genuinely wrong.
- Very specific: line 132
Collecting flow with
.collectAsState(): instead of collectAsStateWithLifecycle() — keeps collecting in the background, wasting work and … - Distinctive: line 150
Adaptivity: run iPhone portrait, iPhone landscape, and iPad / a foldable (or resizable emulator dragged across 600dp and 840dp) — layout …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
Reach for this skill when building or reviewing a native iOS/Android screen in a declarative UI framework (SwiftUI or Jetpack Compose, i.e. Swift/Kotlin — not React Native or Flutter):
- "Build a SwiftUI/Compose list-detail screen with pull-to-refresh"
- "Hoist this view state — the toggle should be controlled by the parent"
- "Add a NavigationStack / Compose Navigation route with a deep link"
- "Make this adapt to iPad / foldable / landscape (two-pane on wide)"
- "Support dark mode + Dynamic Type without truncation"
- "VoiceOver reads this button wrong / TalkBack skips the row"
- "This list janks / recomposes the whole screen on every keystroke"
NOT this skill:
- Cross-platform UI in React Native or Flutter (JSX/Dart, Expo Router, Riverpod/Bloc) → scaffold-cross-platform-app (this skill is native Swift/Kotlin only)
- Web/React components (JSX, hooks, DOM) → build-react-component
- CSS/Tailwind breakpoints and responsive web layout → style-responsive-tailwind
- Auditing a web page against WCAG success criteria → audit-accessibility-wcag
- Server cache, fetching, optimistic mutation, query invalidation → manage-client-server-state (this skill owns UI state, not network state)
- Architecting the token tiers/themes/multi-platform export pipeline → design-token-system (this skill consumes tokens in a screen, doesn't design the system)
- Converting a Figma/design spec into pixel-faithful code → implement-from-design (use this skill for the framework idioms once you have the spec)
- The server send path, payload schema, or token registration for push → implement-push-notifications (this skill owns the in-app deep-link router push taps land in)
- Code signing, build lanes, store upload, phased rollout → ship-mobile-app-store-release
- Profiling/fixing web load metrics (LCP/CLS) → optimize-core-web-vitals
Steps
Pick the container primitive by data shape — never default to a plain stack for collections. Lazy containers virtualize; eager ones build every child up front and jank past ~50 rows.
Need SwiftUI Compose Long/unbounded scrolling list List(free separators, swipe, refresh) orLazyVStackinScrollViewLazyColumn(withkey = { it.id })Small fixed group (≤ ~20, all visible) VStack/Form/SectionColumnScreen chrome (top bar, FAB, snackbar, insets) NavigationStack+.toolbarScaffold(topBar, floatingActionButton, snackbarHost)Grid LazyVGrid(columns:)LazyVerticalGrid(columns = GridCells.Adaptive(160.dp))Overlap / z-stack ZStackBoxAlways set stable item identity (
List(items, id: \.id)/items(list, key = { it.id })) — without it, scroll position and animations break on reorder.One source of truth, hoisted up; flow data down, events up. A child that owns the state it renders is unreusable and untestable. Make leaf views stateless (value + callback); keep state at the lowest common owner.
SwiftUI — child takes
Binding, owns nothing:struct ToggleRow: View { // stateless leaf let title: String @Binding var isOn: Bool var body: some View { Toggle(title, isOn: $isOn) } } // parent owns it: @State private var pushEnabled = false ToggleRow(title: "Push", isOn: $pushEnabled)Compose — hoist with
value+onValueChange, never an internalrememberfor controlled state:@Composable fun ToggleRow(title: String, checked: Boolean, onChecked: (Boolean) -> Unit) { Row { Text(title); Switch(checked = checked, onCheckedChange = onChecked) } // stateless }Concern SwiftUI Compose Local ephemeral UI state @State(private)var x by remember { mutableStateOf(...) }Owned by parent @Bindingvalue+onValueChangelambdaScreen/business state, survives config change @Observableclass (@Stateat owner)ViewModel+StateFlow→collectAsStateWithLifecycle()Survive process death @SceneStorage/@AppStorageSavedStateHandle/rememberSaveableDI'd cross-cutting @EnvironmentCompositionLocal/ hilt-injected VMDefault: screen state lives in
@Observable(iOS 17+) /ViewModel; the view is a pure function of it. Expose immutable state out (val uiState: StateFlow<UiState>), accept intents in (fun onIntent(...)).Type your navigation — no stringly-typed routes for in-app pushes. Drive the stack from a state-bound path so back/deep-link/restore are deterministic.
SwiftUI:
@State private var path = NavigationPath() NavigationStack(path: $path) { List(items) { NavigationLink("\($0.name)", value: $0) } // value, not destination view .navigationDestination(for: Item.self) { ItemDetail(item: $0) } } // deep link: path.append(item) — or .onOpenURL { url in route(url, &path) }Compose (type-safe routes, nav 2.8+ with
@Serializableobjects):@Serializable data class ItemDetail(val id: String) NavHost(nav, startDestination = ItemList) { composable<ItemList> { ItemListScreen(onOpen = { nav.navigate(ItemDetail(it.id)) }) } composable<ItemDetail>(deepLinks = listOf(navDeepLink<ItemDetail>(basePath = "app://item"))) { ItemDetailScreen(it.toRoute<ItemDetail>().id) } }Rules: each tab gets its own back stack; restore a saved stack on tab reselect (don't reset to root); a deep link must rebuild the parent stack so Back has somewhere to go.
- Layout for variable size from the start — respect insets, scale with the user's type setting, branch on width class. Hardcoded heights and a single phone layout break on Dynamic Type / iPad / foldable.
- Safe area / insets: never hardcode status-bar or notch padding. SwiftUI honors safe area by default — only push to edges with
.ignoresSafeArea()deliberately and pad content back. Compose:ScaffoldgivesinnerPadding— apply it; for keyboard useModifier.imePadding()/windowInsetsPadding(...). - Dynamic Type / font scale: use semantic styles (
.font(.body)/MaterialTheme.typography.bodyLarge), not fixedpt/sp. Let text wrap; cap with.lineLimit+.minimumScaleFactor(0.8)only when a hard ceiling exists. Verify at the largest accessibility size. Adaptive width: branch on the class, not a raw
375-px guess. iPad/landscape and wide foldables → two-pane.iOS Android Read width class @Environment(\.horizontalSizeClass)(.compact/.regular)calculateWindowSizeClass(activity).widthSizeClass(Compact/Medium/Expanded)List+detail that adapts NavigationSplitViewtwo-pane when Expanded, singleNavHostwhenCompactBreakpoints compact = phone portrait; regular = iPad/landscape Compact <600dp · Medium 600–840dp · Expanded ≥840dp
- Safe area / insets: never hardcode status-bar or notch padding. SwiftUI honors safe area by default — only push to edges with
- Theme through tokens, not literals — and support dark by deriving, not duplicating. Reference semantic roles so dark mode is automatic.
- iOS: use system semantic colors (
Color(.systemBackground),.primary,.secondary,Color("Brand")from an Asset Catalog with a Dark variant) — they flip with@Environment(\.colorScheme). Icons: SF Symbols (Image(systemName: "trash")) so they match weight/scale. - Android: define a
ColorSchemevia Material 3lightColorScheme()/darkColorScheme()(ordynamicColorScheme(context)for Material You on API 31+), select byisSystemInDarkTheme(), expose throughMaterialTheme. Never readColor(0xFF...)literals inside a composable. - Never gate logic on the literal color; gate on the token/role. One token table, two schemes derived from it.
- iOS: use system semantic colors (
- Accessibility is a build requirement, not a pass. Every interactive element needs a label + role; targets ≥ 44pt (iOS HIG) / ≥ 48dp (Material). Decorative images get no label.
- iOS:
.accessibilityLabel("Delete"),.accessibilityAddTraits(.isButton),.accessibilityHidden(true)for decoration, group a row with.accessibilityElement(children: .combine)so VoiceOver reads it as one unit. - Compose:
Modifier.semantics { contentDescription = "Delete" }(or the param onIcon),contentDescription = nullfor decorativeImage,Modifier.clearAndSetSemantics {}to merge a row,Role.Button/Role.CheckboxviaModifier.semantics { role = ... }. - Don't override the framework focus order unless reading order is genuinely wrong; tappable area must equal visible-or-larger, never smaller than the touch-target minimum.
- iOS:
- Lifecycle & side effects: run effects in the right hook, keyed correctly, and stop fighting recomposition. A composable body /
bodyruns many times — never do I/O, start timers, or mutate state there.- iOS:
.task { await load() }(auto-cancels on disappear) for async load;.onAppear/.onDisappearfor non-async;.onChange(of: query) { … }for reactions. Don't kick network off inbody. - Compose:
LaunchedEffect(key)for suspend work on enter / whenkeychanges;rememberCoroutineScope()for event-triggered launches;DisposableEffectto register+onDisposecleanup;derivedStateOfto avoid recomposing on every upstream tick;produceStateto bridge a callback into state. The key must include every input the effect depends on, or it goes stale. - Stop needless recomposition: read VM state with
collectAsStateWithLifecycle(); pass stable/@Immutabletypes and lambdas; hoist heavy reads out ofitems{}; defer rapidly-changing reads (scroll offset) with a lambda (Modifier.offset { … }) so only the layout phase reruns. SwiftUI equivalent: split big views so a small@Statechange invalidates a small subtree, giveForEachstable ids, mark expensive subviewsEquatable.
- iOS:
- Verify on a real simulator/emulator with previews + the accessibility inspectors (see Verify) before declaring done — previews catch layout, the device catches lifecycle and gesture bugs previews can't.
Common Errors
VStack/Columnfor a long list. Builds every child eagerly → jank and memory blowup. UseLazyVStack/List/LazyColumn.- No stable item key.
LazyColumnwithoutkey=(orListkeyed by index) reorders/animates wrong and loses scroll on insert. Key by a stable id. - State owned in the leaf you want to reuse. Child
@State/internalrememberfor what the parent should control → can't lift, can't test, drifts out of sync. Hoist:Binding/value+onValueChange. remember { mutableStateOf(...) }for screen state. Lost on rotation/process death; doesn't survive nav. Put it in aViewModel(orrememberSaveablefor trivial UI bits).- Collecting flow with
.collectAsState()instead ofcollectAsStateWithLifecycle()— keeps collecting in the background, wasting work and risking stale UI. Use the lifecycle-aware one. - Side effect in
body/composable body. Network ormutableStateOfwrite during composition → infinite recomposition or duplicate loads. Move to.task/LaunchedEffect. - Wrong/empty
LaunchedEffectkey.LaunchedEffect(Unit)that readsidnever reloads whenidchanges; over-keyed restarts constantly. Key on exactly the inputs the effect uses. - Stringly-typed nav routes (
navigate("detail/$id")with manual parsing) — typos compile, args lose types, deep links break silently. Use type-safe routes /value:+navigationDestination(for:). - Single shared back stack across tabs. Switching tabs nukes the other tab's history. Give each tab its own
NavHost/stack and save/restore it. - Hardcoded padding for the notch/status bar / ignoring
innerPadding. Content slides under the bar or the keyboard. Honor safe area / applyScaffoldinnerPadding+imePadding(). - Fixed font sizes /
.lineLimit(1)everywhere. Truncates at large Dynamic Type, fails accessibility. Semantic text styles; allow wrap; scale-factor only as a last resort. - Hardcoded hex colors in views. Dark mode shows white-on-white. Use semantic colors /
MaterialTheme.colorSchemetokens with light+dark schemes. - Touch target smaller than the icon's frame. A 24pt icon with no padding is a 24pt target. Pad to ≥44pt/48dp.
contentDescription/label missing on icon buttons, or set on decorative images. Screen reader says "button" with no name, or narrates clutter. Label actionable elements;null/.accessibilityHidden(true)decoration.- Reading rapidly-changing state (scroll offset, animation) at composition scope. Recomposes the whole subtree every frame. Read it in a lambda (
Modifier.offset { … }) / usederivedStateOf.
Verify
- Builds & previews render:
xcodebuild -scheme <S> -destination 'platform=iOS Simulator,name=iPhone 15' build/./gradlew assembleDebug. SwiftUI#Previewand Compose@Previewshow light and dark variants without crashing. - List performance: scroll a 500+ item list on device — no dropped frames; inserting/removing keeps scroll position. (Compose: Layout Inspector → recomposition counts stay flat per row while scrolling; a row recomposing on unrelated state changes is a fail.)
- State hoisting holds: toggle the child's control, confirm the parent's single source of truth updates and no duplicate/stale copy exists; rotate the device (or trigger config change) — state survives (VM/
rememberSaveable), is not reset. - Navigation & deep link: push → Back returns correctly; cold-launch the deep link (
xcrun simctl openurl booted app://item/42/adb shell am start -a android.intent.action.VIEW -d "app://item/42") lands on the right screen with a sane back stack; switch tabs and return — the other tab's stack is preserved. - Adaptivity: run iPhone portrait, iPhone landscape, and iPad / a foldable (or resizable emulator dragged across 600dp and 840dp) — layout switches single↔two-pane at the size-class boundary, nothing clips or overlaps.
- Dynamic Type / dark: set the largest accessibility text size and dark mode (iOS Settings → Accessibility → Larger Text; emulator font scale 1.3+ / Dark theme) — no truncation, no white-on-white, all controls reachable.
- Screen reader: enable VoiceOver (Accessibility Inspector → audit) / TalkBack — swipe through: every actionable element announces a name + role, decorative content is skipped, focus order is logical, and no target is below 44pt/48dp (Xcode Accessibility Inspector audit / Compose
testTagsAsResourceId+ Accessibility Scanner report zero issues).
Done = the screen builds, previews render light+dark, a 500+ row list scrolls without dropped frames and without per-row recomposition on unrelated changes, state is hoisted and survives a config change, typed navigation + cold deep link land correctly with per-tab back stacks preserved, layout adapts across the size-class boundaries, and the accessibility inspector/scanner reports zero issues at the largest Dynamic Type / font scale.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

