Common/ Shared ViewModel in Kotlin Multiplatform - A Kotlin Multiplatform library that provides shared MVVM for UI applications. Components are lifecycle-aware on Android. Supports Android Parcelable, Kotlin Parcelize, AndroidX SavedStateHandle for restoring state after process death. Easy interoperability with Swift/Objective-C and SwiftUI. Supports Compose Multiplatform Framework (Android, Desktop, Web, iOS, macOS, tvOS, watchOS).
The ViewModel class is a business logic or screen level state holder. It exposes state to the UI and encapsulates related business logic. Its principal advantage is that it caches state and persists it through configuration changes (on Android).
Author: Petrus Nguyễn Thái Học
Liked some of my work? Buy me a coffee (or more likely a beer)
android
.jvm
(must addkotlinx-coroutines-swing
/kotlinx-coroutines-javafx
to your dependencies to make sureDispatchers.Main
available).js
(IR
).Darwin
targets:iosArm64
,iosArm32
,iosX64
,iosSimulatorArm64
.watchosArm32
,watchosArm64
,watchosX64
,watchosX86
,watchosSimulatorArm64
.tvosX64
,tvosSimulatorArm64
,tvosArm64
.macosX64
,macosArm64
.
0.x release docs: https://hoc081098.github.io/kmp-viewmodel/docs/0.x
Snapshot docs: https://hoc081098.github.io/kmp-viewmodel/docs/latest
For more information check out the docs.
For more information check out the docs.
For more information check out the docs.
For more information check out the docs.
- support
SaveStateHandle
(since 0.2.0). - add extensions for
Flow
/StateFlow
, to use the ViewModel easily onios
/macOS
/tvOS
/watchOS
platforms (since 0.3.0). - support
Compose Multiplatform Framework
.
- KMM sample: shares business logic and
ViewHolder
s, using Jetpack Compose for Android and SwiftUi for iOS. - Compose Multiplatform sample: shares
ViewModel
s and integrates withNavigation
in Compose Multiplatform.
MIT License
Copyright (c) 2023 Petrus Nguyễn Thái Học