← スキル一覧に戻る

android-viewmodel
by new-silvermoon
A collection of standardized Agent Skills to teach GitHub Copilot & Claude about modern Android development (Kotlin, Jetpack Compose, etc.).
⭐ 14🍴 2📅 2026年1月23日
SKILL.md
name: android-viewmodel description: Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events.
Android ViewModel & State Management
Instructions
Use ViewModel to hold state and business logic. It must outlive configuration changes.
1. UI State (StateFlow)
- What: Represents the persistent state of the UI (e.g.,
Loading,Success(data),Error). - Type:
StateFlow<UiState>. - Initialization: Must have an initial value.
- Exposure: Expose as a read-only
StateFlowbacking a privateMutableStateFlow.private val _uiState = MutableStateFlow<UiState>(UiState.Loading) val uiState: StateFlow<UiState> = _uiState.asStateFlow() - Updates: Update state using
.update { oldState -> ... }for thread safety.
2. One-Off Events (SharedFlow)
- What: Transient events like "Show Toast", "Navigate to Screen", "Show Snackbar".
- Type:
SharedFlow<UiEvent>. - Configuration: Must use
replay = 0to prevent events from re-triggering on screen rotation.private val _uiEvent = MutableSharedFlow<UiEvent>(replay = 0) val uiEvent: SharedFlow<UiEvent> = _uiEvent.asSharedFlow() - Sending: Use
.emit(event)(suspend) or.tryEmit(event).
3. Collecting in UI
- Compose: Use
collectAsStateWithLifecycle()forStateFlow.
Forval state by viewModel.uiState.collectAsStateWithLifecycle()SharedFlow, useLaunchedEffectwithLocalLifecycleOwner. - Views (XML): Use
repeatOnLifecycle(Lifecycle.State.STARTED)within a coroutine.
4. Scope
- Use
viewModelScopefor all coroutines started by the ViewModel. - Ideally, specific operations should be delegated to UseCases or Repositories.
スコア
総合スコア
65/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
✓説明文
100文字以上の説明がある
+10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
○言語
プログラミング言語が設定されている
0/5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です