Kmp viewmodel
🔆 Kotlin Multiplatform ViewModel. Kotlin Multiplatform MVVM. 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.
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 project is written primarily in Kotlin, distributed under the MIT License license, first published in 2023. Key topics include: kmm, kmm-example, kmm-library, kmm-mvvm, kmm-sample.
kmp-viewmodel 🔆
Kotlin Multiplatform ViewModel - Kotlin Multiplatform MVVM - Compose Multiplatform ViewModel
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).
kmp-viewmodel and Navigation for JetBrains Compose Multiplatform 👉 https://github.com/hoc081098/solivagant
<img src="https://img.shields.io/nexus/snapshots/https/s01.oss.sonatype.org/io.github.hoc081098/kmp-viewmodel.svg?label=latest%20snapshot"/>
Author: Petrus Nguyễn Thái Học
Liked some of my work? Buy me a coffee (or more likely a beer)
<a href="https://www.buymeacoffee.com/hoc081098" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" height=64></a>
Supported targets
android.jvm(must addkotlinx-coroutines-swing/kotlinx-coroutines-javafxto your dependencies to
make sureDispatchers.Mainavailable).
[!NOTE]
If you are targetingDesktopand:
- not using
JetBrains Compose Multiplatform, you should provide the dependencyorg.jetbrains.kotlinx:kotlinx-coroutines-swingororg.jetbrains.kotlinx:kotlinx-coroutines-javafx.- using
JetBrains Compose Multiplatform, you should provideorg.jetbrains.kotlinx:kotlinx-coroutines-swing.Because the
ViewModel.viewModelScopedepends onDispatchers.Mainprovided by that libraries on Desktop.
js(IR).wasmJs.Darwintargets:iosArm64,iosX64,iosSimulatorArm64.watchosArm32,watchosArm64,watchosX64,watchosSimulatorArm64.tvosX64,tvosSimulatorArm64,tvosArm64.macosX64,macosArm64.
Docs
0.x release docs: https://hoc081098.github.io/kmp-viewmodel/docs/0.x
Snapshot docs: https://hoc081098.github.io/kmp-viewmodel/docs/latest
Getting started
1. kmp-viewmodel library
For more information check out the docs.
2. kmp-viewmodel-savedstate library
For more information check out the docs.
3. kmp-viewmodel and Swift interoperability
For more information check out the docs.
4. kmp-viewmodel-compose library
For more information check out the docs.
5. kmp-viewmodel-koin-compose library
For more information check out the docs.
6. kmp-viewmodel-koject-compose library
For more information check out the docs.
7. kmp-viewmodel and Navigation for JetBrains Compose Multiplatform.
For more information check out https://github.com/hoc081098/solivagant library.
Samples
For more information check out the docs.
- KMM sample: shares business logic and
ViewHolders, using Jetpack Compose for Android and SwiftUi for iOS. - Compose Multiplatform Koin sample: shares
ViewModels and integrates withNavigationin Compose Multiplatform. It usesKoinfor DI. - Compose Multiplatform Koject sample: shares
ViewModels and integrates withNavigationin Compose Multiplatform. It usesKojectfor DI. - Compose Multiplatform KmpViewModel KMM Unsplash Sample: A KMP template of the Unsplash App using Compose multiplatform for Android, Desktop, iOS. Share everything including data, domain, presentation, and UI.
- 🍭 GithubSearchKMM: Github Repos Search KMM for Android and iOS. Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture.
Roadmap
- support
SaveStateHandle(since 0.2.0). - add extensions for
Flow/StateFlow, to use the ViewModel easily onios/macOS/tvOS/watchOSplatforms
(since 0.3.0). - support
Compose Multiplatform Framework(since 0.5.0). - support
Koinintegration with ViewModel andJetBrains Compose Multiplatform(since 0.6.2).
License
licenseMIT License Copyright (c) 2023-2024 Petrus Nguyễn Thái Học
Contributors
Showing top 3 contributors by commit count.
