Mobile MVVM
БесплатноБез исполняемых скриптовНе проверенDesigns, implements and tests screens with MVVM on Android (Compose, ViewModel, StateFlow, Hilt; legacy LiveData), iOS (SwiftUI, @Observable, @MainActor) and…
от ahmadhussain0335255 установок в других каталогахОб этом скилле
MVVM for mobile apps
Build screens where the UI is a plain function of one immutable state object, the ViewModel owns that state and the screen-scoped work, and data comes from repositories that the ViewModel receives by injection. The result survives rotation and process death, renders the same state the same way every time, and is testable without a device.
When to use
- A new screen or feature needs a ViewModel, state holder or presentation layer.
- An existing screen has state bugs: lost input on rotation or process death, double loads, stale UI, snackbars shown twice or never.
- Migrating Java + LiveData + XML screens to Kotlin + StateFlow + Compose,
ObservableObjectto@Observable, orsetStatescreens to Riverpod or provider. - Reviewing a ViewModel for layer leaks, lifecycle issues or untestable code.
- Choosing between MVVM, MVI and MVC for a screen or a codebase.
Not for: screens with many interacting events, strict event ordering or debounced concurrent requests
(use mobile-mvi), or legacy UIKit and Activity-centric code you only maintain (use mobile-mvc).
When to choose MVVM vs MVI vs MVC
| MVVM | MVI | MVC | |
|---|---|---|---|
| State | One UiState per screen (or a few observable properties) |
One immutable State, changed only by a reducer |
Spread across controller and views |
| How UI talks to logic | Calls named ViewModel functions (onRefresh()) |
Sends one sealed Intent type |
Controller handles view callbacks directly |
| Side effects | Inside ViewModel functions | Explicit effects outside a pure reducer | Inside the controller |
| Boilerplate | Low | Medium to high | Lowest at first, grows fast |
| Testing | ViewModel tests with fakes | Pure reducer tests plus effect tests | Hard, logic bound to views |
| Good fit | Most screens: lists, details, forms, settings | Search with debounce, editors, wizards, chat, real-time device dashboards | Prototypes, small UIKit or Activity code already in that style |
| Platform fit | Android Architecture guidance, SwiftUI @Observable, Riverpod, provider |
Compose + StateFlow store, TCA, Bloc |
UIKit UIViewController, legacy Activities |
Rules of thumb:
- Default to MVVM with a single
UiState. It already gives unidirectional data flow. - Move a screen to MVI when ViewModel functions start racing each other or the state transitions need to be auditable and tested as pure functions.
- Do not mix patterns inside one screen. Mixing across screens is fine.
Layers
UI (Composable, SwiftUI View, Widget) renders UiState, forwards user events
| events ^ UiState
v |
ViewModel owns screen state and screen-scoped work, maps domain data to UiState
|
v
Use cases (optional) business rules reused by several ViewModels, or too complex for one
|
v
Repository single source of truth, merges sources, maps DTOs and entities to domain models
|
v
Data sources network, database, BLE, files, platform APIs
- Dependencies point down only. Lower layers never import UI or ViewModel types.
- Use cases are optional. Add one when the logic is shared or non-trivial, not as a pass-through.
- The ViewModel lives as long as the screen (navigation destination), not as long as the view instance.
Workflow
- Confirm MVVM fits the screen using the table above.
- Load the reference for the platform before writing code: Kotlin and Compose, Java with LiveData and ViewBinding, Swift and SwiftUI, Dart with Riverpod or provider.
- Write the
UiState: everything the screen renders, with defaults. Derive values (filtered lists, button enabled flags) instead of storing them twice. - List the user events and name one ViewModel function per event (
onRefresh,onFavoriteClick). - Define the repository interface in domain types, plus a fake for tests and previews.
- Implement the ViewModel: combine sources into
UiState, handle events, map errors to state. - Wire DI and ownership (Hilt,
@State, Riverpod provider,ChangeNotifierProvider). - Build the UI as a stateless function of
UiStateplus callbacks. Preview it with fake states. - Save small user input that must survive process death (filters, query, selected id).
- Write ViewModel tests with fakes, run the existing test suite and report failures.
Rules
1. One immutable UiState per screen, exposed read-only
Several independent mutable properties drift out of sync and let the UI write state.
Kotlin:
// BAD: public mutable state, three flows that can disagree
val devices = MutableStateFlow<List<Device>>(emptyList())
val isLoading = MutableStateFlow(false)
val error = MutableStateFlow<String?>(null)
// GOOD
data class DeviceListUiState(
val devices: List<Device> = emptyList(),
val isLoading: Boolean = false,
val userMessage: UserM
Установить Mobile MVVM в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Mobile MVVM?
Designs, implements and tests screens with MVVM on Android (Compose, ViewModel, StateFlow, Hilt; legacy LiveData), iOS (SwiftUI, @Observable, @MainActor) and Flutter (Riverpod, ChangeNotifier): single immutable UI state, one-off events, lifecycle-aware collection and ViewModel tests. Use when building or refactoring a screen's state handling, or choosing between MVVM, MVI and MVC.
Как установить скилл Mobile MVVM?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Mobile MVVM запускает скрипты?
Нет, скилл состоит только из инструкций (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