client/.github/skills/android-viewmodel/SKILL.md
Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events.
npx skillsauth add ahaodev/heji android-viewmodelInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use ViewModel to hold state and business logic. It must outlive configuration changes.
Loading, Success(data), Error).StateFlow<UiState>.StateFlow backing a private MutableStateFlow.
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
.update { oldState -> ... } for thread safety.SharedFlow<UiEvent>.replay = 0 to prevent events from re-triggering on screen rotation.
private val _uiEvent = MutableSharedFlow<UiEvent>(replay = 0)
val uiEvent: SharedFlow<UiEvent> = _uiEvent.asSharedFlow()
.emit(event) (suspend) or .tryEmit(event).collectAsStateWithLifecycle() for StateFlow.
val state by viewModel.uiState.collectAsStateWithLifecycle()
For SharedFlow, use LaunchedEffect with LocalLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) within a coroutine.viewModelScope for all coroutines started by the ViewModel.development
Apply Shadmin feature-development standards (backend Go/Gin/Ent + frontend React/TS). Use when adding/modifying features, CRUD modules, API routes/controllers/usecases/repositories, Ent schemas, or web pages/routes.
data-ai
Convert Android XML layouts to Jetpack Compose. Use when asked to migrate Views to Compose, convert XML to Composables, or modernize UI from View system to Compose.
development
Kotlin Coroutines review and remediation for Android. Use when asked to review concurrency usage, fix coroutine-related bugs, improve thread safety, or resolve lifecycle issues in Kotlin/Android code.
development
Debug and optimize Android/Gradle build performance. Use when builds are slow, investigating CI/CD performance, analyzing build scans, or identifying compilation bottlenecks.