android-compose-patterns
БесплатноБез исполняемых скриптовНе проверенUse when building native Android with Jetpack Compose - stateless composables, state hoisting, ViewModel-owned state, edge-to-edge, predictive back, adaptive…
от makifbaysal★ 123 звезды на GitHubОб этом скилле
Jetpack Compose Patterns
Overview
Native Android (Jetpack Compose) is chosen when a task needs deep Android integration or the app is already native (see native-vs-flutter-decision). Same discipline as Flutter/SwiftUI: small stateless composables, state hoisted out, reusable atomic components.
Core principle: Composables are stateless functions of state. State is hoisted to a ViewModel; composables emit events upward.
Rules
- Stateless composables + state hoisting. A composable takes its state as parameters and exposes callbacks (
onXxx) — it does not own app state. The screen-level composable connects aViewModelto the stateless UI. ViewModelowns state and logic, exposed asStateFlow/UiState; the composable collects it withcollectAsStateWithLifecycle(). Networking/business rules live in the ViewModel + repository, never in the composable.- Model UI state as a sealed hierarchy:
Loading | Data | Empty | Error—whenover it renders every branch. No happy-path-only screens. - Atomic components: shared library of reusable composables (atoms → molecules → organisms). Reuse before building; grep before adding.
- Material theme, not hardcoded values:
MaterialTheme.colorScheme/typography/ a spacing tokens object (MaterialTheme.spacing, seemobile-design-system-foundation) — never scatteredColor(0xFF...)and magicdp. Support dark theme + dynamic color. remember/derivedStateOfto avoid recomputation; hoistremembered state only when it's genuinely local (scroll, text field).@Previewreusable composables in their key states, and across the matrix (see below).
Edge-to-edge (enforced from targetSdk 35)
- Call
enableEdgeToEdge()beforesetContentin the activity — the opt-out is gone at targetSdk 35+. - Consume insets at the
Scaffold: use itsinnerPaddingandModifier.consumeWindowInsets(innerPadding)on the content so a nested scrollable doesn't double-apply it. - IME padding: apply
Modifier.imePadding()once, at the container that should move with the keyboard — applying it a second time further down the tree produces extra empty space. android:windowSoftInputMode="adjustResize"in the manifest for screens with text input.NavigationSuiteScaffolddoes not automatically propagate its padding to the content slot — apply insets explicitly inside it, don't assume it's handled.
Predictive back (default at targetSdk 36)
onBackPressed()/OnBackPressedCallbackwithoutisEnabledtoggling is not called the same way once predictive back is the default — useBackHandler(simple) orPredictiveBackHandler(custom transition) in Compose, or Navigation 3's built-in handling.- Verify back navigation in this run rather than assuming the old override still fires.
Adaptive layout
currentWindowAdaptiveInfo().windowSizeClassto branch layout by available width/height — never byConfiguration.orientationor a hardcoded device check.NavigationSuiteScaffoldswitches a bottom nav bar to a nav rail automatically at the window-size-class breakpoint — prefer it over hand-rolling the switch.GridCells.Adaptive(minWidth)for grids that should reflow by available width.- Android 16 (opt-out via
PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY) and Android 17/API 37 (no opt-out) ignorescreenOrientation/resizeableActivityrestrictions on screens ≥600dp — design every screen to work in both orientations and at tablet width; don't rely on an orientation lock to avoid building the wider layout.
Previews and tests across the matrix
@PreviewScreenSizes,@PreviewFontScale,@PreviewLightDark, or a custom multi-preview withDevices.PHONE/Devices.TABLET— seemobile-visual-self-reviewfor the full size/text-scale/dark matrix.DeviceConfigurationOverride(ForcedSize(...) then FontScale(...) then DarkMode(...))for instrumented matrix tests.rule.enableAccessibilityChecks()on an API 34+ device/emulator before UI-mutating test actions (inconclusive on Robolectric — say so if that's all you ran); seemobile-accessibility.- "Run screenshot tests but do not update reference images" to "fix" a failure — a changed golden is a visual regression until a human confirms it's intended.
Semantics
contentDescriptionon everyImage/Iconthat carries meaning;nullexplicitly for a purely decorative one.Modifier.semantics(mergeDescendants = true)on a composite row so a screen reader announces it once.- Touch targets ≥48dp —
Modifier.size/minimumInteractiveComponentSize().
Worked Example
// ViewModel owns state + logic (unit-testable, no Compose)
class TaskListViewModel(private val repo: TaskRepository) : ViewModel() {
private val _state = MutableStateFlow<UiState<List<Task>>>(UiState.Loading)
val state: StateFlow<UiState<List<Task>>> = _state
fun load() = viewModelScope.launch {
_state.value = UiState.Loading
Установить android-compose-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл android-compose-patterns?
Use when building native Android with Jetpack Compose - stateless composables, state hoisting, ViewModel-owned state, edge-to-edge, predictive back, adaptive layout, atomic components, and Material theming over hardcoded values
Как установить скилл android-compose-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл android-compose-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic