Coder Social home page Coder Social logo

hoc081098 / kmp-viewmodel Goto Github PK

View Code? Open in Web Editor NEW
106.0 3.0 5.0 4.56 MB

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

Home Page: https://hoc081098.github.io/kmp-viewmodel/docs/0.x/

License: MIT License

Kotlin 99.23% Shell 0.13% Swift 0.54% HTML 0.10%
kotlin-multiplatform kmm kmm-example kmm-library kmm-mvvm kmm-sample kmp-redux kmp-viewmodel kotlin-multiplaform kotlin-multiplatform-library kotlin-multiplatform-mobile kotlin-multiplatform-template mvvm mvvm-architecture kmp-mvvm kmm-viewmodel kmp-library kotlin-multiplatform-compose-viewmodel kotlin-multiplatform-mvvm kotlin-multiplatform-viewmodel

kmp-viewmodel's Introduction

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

maven-central codecov Build and publish snapshot Build sample Publish Release License: MIT Kotlin version KotlinX Coroutines version Compose Multiplatform version Hits badge badge 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).

Note

If you are targeting Desktop and:

  • not using JetBrains Compose Multiplatform, you should provide the dependency org.jetbrains.kotlinx:kotlinx-coroutines-swing or org.jetbrains.kotlinx:kotlinx-coroutines-javafx.
  • using JetBrains Compose Multiplatform, you should provide org.jetbrains.kotlinx:kotlinx-coroutines-swing.

Because the ViewModel.viewModelScope depends on Dispatchers.Main provided by that libraries on Desktop.

  • js (IR).
  • wasmJs.
  • Darwin targets:
    • iosArm64, iosX64, iosSimulatorArm64.
    • watchosArm32, watchosArm64, watchosX64, 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.

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.

Sample

  • KMM sample: shares business logic and ViewHolders, using Jetpack Compose for Android and SwiftUi for iOS.
  • Compose Multiplatform Koin sample: shares ViewModels and integrates with Navigation in Compose Multiplatform. It uses Koin for DI.
  • Compose Multiplatform Koject sample: shares ViewModels and integrates with Navigation in Compose Multiplatform. It uses Koject for 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 on ios/macOS/tvOS/watchOS platforms (since 0.3.0).
  • support Compose Multiplatform Framework (since 0.5.0).
  • support Koin integration with ViewModel and JetBrains Compose Multiplatform (since 0.6.2).

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.