Skip to content

🔆 Shared ViewModel in Kotlin Multiplatform - A Kotlin Multiplatform library that provides shared MVVM for UI applications. Components are lifecycle-aware on Android.

License

Notifications You must be signed in to change notification settings

Kotlin-Android-Open-Source/kmp-viewmodel

 
 

Repository files navigation

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).

maven-central codecov Build and publish snapshot Build sample Publish Release License: MIT Kotlin version KotlinX Coroutines version Hits badge badge badge badge badge badge badge

Liked some of my work? Buy me a coffee (or more likely a beer)

Buy Me A Coffee

Supported targets

  • android.
  • jvm (must add kotlinx-coroutines-swing/kotlinx-coroutines-javafx to your dependencies to make sure Dispatchers.Main available).
  • js (IR).
  • Darwin targets:
    • iosArm64, iosArm32, iosX64, iosSimulatorArm64.
    • watchosArm32, watchosArm64, watchosX64, watchosX86, watchosSimulatorArm64.
    • tvosX64, tvosSimulatorArm64, tvosArm64.
    • macosX64, macosArm64.

Docs

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.

Roadmap

  • support SaveStateHandle (since 0.2.0).
  • add extensions for Flow/StateFlow, to use the ViewModel easily on ios/macOS/tvOS/watchOS platforms (since 0.3.0).
  • support Compose Multiplatform Framework.

Sample

  • KMM sample: shares business logic and ViewHolders, using Jetpack Compose for Android and SwiftUi for iOS.
  • Compose Multiplatform sample: shares ViewModels and integrates with Navigation in Compose Multiplatform.

License

MIT License
Copyright (c) 2023 Petrus Nguyễn Thái Học

About

🔆 Shared ViewModel in Kotlin Multiplatform - A Kotlin Multiplatform library that provides shared MVVM for UI applications. Components are lifecycle-aware on Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 99.2%
  • Other 0.8%