shekhar23/claude-zero-to-hero-android-kmp/android-kmp-viewmodel

Claude Code and agent skill by shekhar23/claude-zero-to-hero-android-kmp

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Sharing ViewModel logic across Android and iOS in KMP — CommonViewModel base, StateFlow in shared code, platform wrappers for iOS consumption. Use when building shared presentation logic, moving ViewModel to commonMain, or exposing Flow to Swift. Trigger on: "shared ViewModel", "KMP ViewModel", "commonMain ViewModel", "StateFlow iOS", "KMP presentation".

Install

npx vskill@latest install shekhar23/claude-zero-to-hero-android-kmp/android-kmp-viewmodel

SKILL.md

KMP ViewModel

Strategy

Keep ViewModel class on Android (it owns viewModelScope). Move all state logic to a platform-agnostic Presenter or CommonViewModel in commonMain that takes an explicit CoroutineScope.

CommonViewModel (commonMain)

kotlin
// commonMain — core:domain or feature module
abstract class CommonViewModel {
private val viewModelScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
protected fun launch(block: suspend CoroutineScope.() -> Unit): Job =
viewModelScope.launch(block = block)
open fun onCleared() {
viewModelScope.cancel()
}
}

Android ViewModel wraps it

kotlin
// androidMain
class TaskListViewModel(
private val getTasks: GetTasksUseCase,
) : ViewModel() {
private val _state = MutableStateFlow(TaskListState())
val state: StateFlow<TaskListState> = _state.asStateFlow()
init {
viewModelScope.launch {
getTasks().collect { tasks ->
_state.update { it.copy(tasks = tasks) }
}
}
}
}

iOS Swift wrapper (StateFlow → Combine)

kotlin
// iosMain — thin wrapper so Swift can observe
class TaskListIosViewModel(
private val getTasks: GetTasksUseCase,
) : CommonViewModel() {
private val _state = MutableStateFlow(TaskListState())
val state: StateFlow<TaskListState> = _state.asStateFlow()
init {
launch {
getTasks().collect { tasks ->
_state.update { it.copy(tasks = tasks) }
}
}
}
}
swift
// Swift — consume the StateFlow via a helper
let vm = TaskListIosViewModel(getTasks: ...)
let publisher = vm.state.toPublisher() // use KMP-NativeCoroutines or manual wrapper

Recommended library

KMP-NativeCoroutines generates Swift async/await wrappers for StateFlow and Flow automatically.

kotlin
// commonMain
import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState
abstract class CommonViewModel {
@NativeCoroutinesState
abstract val state: StateFlow<*>
}

Checklist

  • [ ] CommonViewModel in commonMain, no Android imports
  • [ ] Android ViewModel delegates to shared logic or shares StateFlow
  • [ ] iOS wrapper calls onCleared() in deinit
  • [ ] No LiveData in shared code — StateFlow only
  • [ ] Use KMP-NativeCoroutines or equivalent for Swift consumption

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
9
Repository forks
5
7-day trend score
12

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/shekhar23/claude-zero-to-hero-android-kmp/android-kmp-viewmodel/badge)](https://verified-skill.com/skills/shekhar23/claude-zero-to-hero-android-kmp/android-kmp-viewmodel)

Something wrong with this skill or its page? Tell us.