All Projects → dbaroncelli → D-KMP-sample

dbaroncelli / D-KMP-sample

Licence: Apache-2.0 license
D-KMP Architecture official sample: it uses a shared KMP ViewModel and Navigation for Compose and SwiftUI apps.

Programming Languages

kotlin
9241 projects
swift
15916 projects

Projects that are alternatives of or similar to D-KMP-sample

tv-maniac
Tv-Maniac is a Multiplatform app (Android & iOS) for viewing TV Shows from TMDB.
Stars: ✭ 55 (-91.35%)
Mutual labels:  kmp, kotlin-multiplatform, swiftui, jetpack-compose, ktor-client, kmm
kmm
Rick & Morty Kotlin Multiplatform Mobile: Ktor, Sqldelight, Koin, Flow, MVI, SwiftUI, Compose
Stars: ✭ 52 (-91.82%)
Mutual labels:  sqldelight, mvi, kotlin-multiplatform, swiftui, jetpack-compose, kmm
StarWars
Minimal GraphQL based Jetpack Compose, Wear Compose and SwiftUI Kotlin Multiplatform sample (using StarWars endpoint - https://graphql.org/swapi-graphql)
Stars: ✭ 165 (-74.06%)
Mutual labels:  kotlin-multiplatform, swiftui, jetpack-compose, kmm, kotlin-multiplatform-mobile
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (-94.18%)
Mutual labels:  sqldelight, mvi, kotlin-multiplatform, jetpack-compose, kmm
chip-8
Jetpack Compose and SwiftUI based Kotlin Multiplatform fork of https://github.com/cbeust/chip-8 (Chip-8 Emulator)
Stars: ✭ 36 (-94.34%)
Mutual labels:  kotlin-multiplatform, swiftui, jetpack-compose, compose-desktop
Notflix
Kotlin Multiplatform playground
Stars: ✭ 272 (-57.23%)
Mutual labels:  kotlin-multiplatform, jetpack-compose, ktor-client, multiplatform-settings
KMP-NativeCoroutines
Library to use Kotlin Coroutines from Swift code in KMP apps
Stars: ✭ 502 (-21.07%)
Mutual labels:  kmp, kotlin-multiplatform, kmm, kotlin-multiplatform-mobile
ToDometer Multiplatform
WIP Kotlin Multiplatform project: A meter to-do list built with Android Jetpack, Compose UI Multiplatform, Wear Compose, SQLDelight, Koin Multiplatform, SwiftUI, Ktor Server / Client, Exposed...
Stars: ✭ 145 (-77.2%)
Mutual labels:  sqldelight, kmp, kotlin-multiplatform, jetpack-compose
kmm-production-sample
This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you can download it from the App Store and Google Play. It's been designed to demonstrate how KMM can be used in real production projects.
Stars: ✭ 1,476 (+132.08%)
Mutual labels:  kotlin-multiplatform, jetpack-compose, kmm
CompleteKotlin
Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms.
Stars: ✭ 236 (-62.89%)
Mutual labels:  kotlin-multiplatform, kmm, kotlin-multiplatform-mobile
PreCompose
Compose Multiplatform Navigation && ViewModel
Stars: ✭ 150 (-76.42%)
Mutual labels:  kotlin-multiplatform, jetpack-compose, compose-desktop
DagashiApp
Unofficial Android Dagashi Android/iOS app.
Stars: ✭ 32 (-94.97%)
Mutual labels:  kotlin-multiplatform, swiftui, jetpack-compose
Einsen
🎯 Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of Jetpack Compose with Modern Android Architecture Components & MVVM Architecture.
Stars: ✭ 821 (+29.09%)
Mutual labels:  declarative-ui, stateflow, jetpack-compose
Coffeegram
Android app using Jetpack Compose together with StateFlow and MVI
Stars: ✭ 155 (-75.63%)
Mutual labels:  declarative-ui, mvi, jetpack-compose
kinsight-multiplatform
Kotlin Multiplatform Concept - iOS, MacOS, WatchOS (SwiftUI), Android (phone and Wear OS), JVM Web Server - Alpha Capture
Stars: ✭ 38 (-94.03%)
Mutual labels:  kotlin-multiplatform, swiftui, jetpack-compose
TMDbMultiplatform
Step-by-step guide on Kotlin Multiplatform
Stars: ✭ 86 (-86.48%)
Mutual labels:  kmp, kotlin-multiplatform, kmm
Paper
A minimal notes application in Jetpack Compose with MVVM architecture. Built with components like DataStore, Coroutines, ViewModel, LiveData, Room, Navigation-Compose, Coil, koin etc.
Stars: ✭ 122 (-80.82%)
Mutual labels:  stateflow, jetpack-compose
Sqldelight
SQLDelight - Generates typesafe Kotlin APIs from SQL
Stars: ✭ 4,333 (+581.29%)
Mutual labels:  sqldelight, kotlin-multiplatform
SSComposeCookBook
A Collection of major Jetpack compose UI components which are commonly used.🎉🔝👌
Stars: ✭ 386 (-39.31%)
Mutual labels:  declarative-ui, jetpack-compose
Wiggles
🐶 Beautiful Puppy adoption app with Jetpack Compose #AndroidDevChallenge
Stars: ✭ 365 (-42.61%)
Mutual labels:  declarative-ui, jetpack-compose

D-KMP architecture - official sample

This is the official sample of the D-KMP architecture, presenting a simple master/detail app, for Android, iOS and Desktop.
(the Web version will be added at a later stage, when "Compose for Web" and "Kotlin/Wasm" become more mature)

Key features of the D-KMP architecture:

  • it uses the latest declarative UI toolkits: Compose for Android and SwiftUI for iOS
  • it fully shares the ViewModel (including navigation logic and data layer) via Kotlin MultiPlatform
  • coroutine scopes are cancelled/reinitialized automatically, based on the current active screens and the app lifecycle (using LifecycleObserver on Android and the SwiftUI lifecycle on iOS)
  • it implements the MVI pattern and the unidirectional data flow
  • it implements the CQRS pattern, by providing Command functions (via Events and Navigation) and Query functions (via StateProviders)
  • it uses Kotlin's StateFlow to trigger UI layer recompositions
  • the navigation state is processed in the shared code, and then exposed to the UI layer:
    • on SwiftUI it seamlessly integrates with the new iOS 16 navigation patterns (NavigationStack and/or NavigationSplitView)
    • on Compose it's a "remembered" data class which works on any platform (unlike Jetpack Navigation, which only works on Android)

you can find more info on these articles:

Data sources used by this sample:

these are other data sources, not used by this sample, for which popular KMP libraries exist:

Instructions to write your own D-KMP app:

If you want to create your own app using the D-KMP Architecture, here are the instructions you need:

SHARED CODE:

View Model

  • 🛠️ in the viewmodel/screens folder: create a folder for each screen of the app, containing these 3 files (as shown in the sample app structure above):
    • screenEvents.kt, where the event functions for that screen are defined
    • screenInit.kt, where the initialization settings for that screen are defined
    • screenState.kt, where the data class of the state for that screen is defined
  • 🛠️ in the NavigationSettings.kt file in the screens folder, you should define your level 1 navigation and other settings
  • 🛠️ in the ScreenEnum.kt file in the screens folder, you should define the enum with all screens in your app
  • the ScreenInitSettings.kt file in the screens folder doesn't need to be modified
  • the 6 files in the viewmodel folder (DKMPViewModel.kt, Events.kt, Navigation.kt, ScreenIdentifier.kt, StateManager.kt, StateProviders.kt) don't need to be modified
  • also DKMPViewModelForAndroid.kt in androidMain and DKMPViewModelForIos.kt in iosMain don't need to be modified

Data Layer

  • 🛠️ in the datalayer/functions folder: create a file for each repository function to be called by the ViewModel's StateReducers
  • 🛠️ in the datalayer/objects folder: create a file for each data class used by the repository functions
  • 🛠️ in the datalayer/sources folder: create a folder for each datasource, where the datasource-specific functions (called by the repository functions) are defined
  • the datalayer/Repository.kt file should be modified only in case you want to add an extra datasource



PLATFORM-SPECIFIC CODE:

Android

Schermata 2021-06-26 alle 16 54 32

Schermata 2021-06-26 alle 17 03 13

  • the App.kt file doesn't need to be modified
  • the MainActivity.kt file doesn't need to be modified
  • The composables are used by both Android and Desktop apps:
    • 🛠️ the Level1BottomBar.kt and Level1NavigationRail.kt files in the navigation/bars folder should be modified to custom the Navigation bars items
    • the TopBar.kt file in the navigation/bars folder doesn't need to be modified
    • the OnePane.kt and TwoPane.kt files in the navigation/templates folder don't need to be modified
    • the HandleBackButton.kt file in the navigation folder doesn't need to be modified
    • the Router.kt file in the navigation folder doesn't need to be modified
    • 🛠️ in the ScreenPicker.kt file in the navigation folder, you should define the screen composables in your app
    • 🛠️ in the screens folder: create a folder for each screen of the app, containing all composables for that screen
    • the MainComposable.kt file doesn't need to be modified

iOS

ios-files

  • 🛠️ the Level1BottomBar.swift and Level1NavigationRail.swift files in the composables/navigation/bars folder should be modified to custom the Navigation bars items
  • the TopBar.swift file in the composables/navigation/bars folder doesn't need to be modified
  • the OnePane.swift and TwoPane.swift files in the composables/navigation/templates folder don't need to be modified
  • the Router.swift file in the composables/navigation folder doesn't need to be modified
  • 🛠️ in the ScreenPicker.swift file in the views/navigation folder, you should define the screen composables in your app
  • 🛠️ in the views/screens folder: create a folder for each screen of the app, containing all SwiftUI views for that screen
  • the App.swift file doesn't need to be modified
  • the AppObservableObject.swift file doesn't need to be modified

Desktop

Schermata 2021-06-26 alle 16 54 15

Schermata 2021-06-26 alle 17 03 13

  • the main.kt file doesn't need to be modified
  • The composables are used by both Android and Desktop apps:

Web (not yet implemented)

  • The best technology to implement a Web App in Kotlin will be Compose for Web backed by Kotlin/Wasm. However Kotlin/Wasm is still at a very early stage: the first version was just released in February 2023, with Kotlin 1.8.20.
  • Compose For Web and Kotlin/Wasm will allow us to build Compose projects seamlessly for the Web, using the same composables we are already using for the Desktop and Android.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].