# 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**.<br>
(*the **Web** version will be added at a later stage, when "Compose for Web" becomes [more mature](#web-not-yet-implemented)*)
For more info on the D-KMP Architecture, please read the relevant [Medium article](https://danielebaroncelli.medium.com/the-future-of-apps-declarative-uis-with-kotlin-multiplatform-d-kmp-part-1-3-c0e1530a5343).
<img width="500" src="https://user-images.githubusercontent.com/5320104/118643793-4c424900-b7dd-11eb-85c7-1f55b06da6aa.png"></img>
**Note**: in order to run the sample you should use the latest **Android Studio** [Canary build](https://developer.android.com/studio/preview).
## 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
## Data sources used by this sample:
- **webservices** (using [Ktor Http Client](https://ktor.io/docs/client.html))
- **local db** (using [SqlDelight](https://github.com/cashapp/sqldelight))
- **local settings** (using [MultiplaformSettings](https://github.com/russhwolf/multiplatform-settings))
#### other popular KMP libraries for connecting to different data sources:
- **realtime db** (using [Firestore](https://github.com/GitLiveApp/firebase-kotlin-sdk))
- **graphQL** (using [Apollo GraphQL](https://github.com/apollographql/apollo-android))
- **device bluetooth** (using [Kable]( https://github.com/JuulLabs/kable))
- etc...
## 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:
<br>
### SHARED CODE:
#### View Model
<img width="272" src="https://user-images.githubusercontent.com/5320104/118641163-194a8600-b7da-11eb-9bdd-b59e34392d36.png"></img>
- :hammer_and_wrench: 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):
- _screen_**Events.kt**, where the event functions for that screen are defined
- _screen_**Init.kt**, where the initialization settings for that screen are defined
- _screen_**State.kt**, where the data class of the state for that screen is defined
- :hammer_and_wrench: in the **NavigationSettings.kt** file in the **screens** folder, you should define your level 1 navigation and other settings
- :hammer_and_wrench: in the **ScreenEnum.kt** file in the **screens** folder, you should define the enum with all screens in your app
- :white_check_mark: the **ScreenInitSettings.kt** file in the **screens** folder doesn't need to be modified
- :white_check_mark: 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
- :white_check_mark: also **DKMPViewModelForAndroid.kt** in _androidMain_ and **DKMPViewModelForIos.kt** in _iosMain_ don't need to be modified
#### Data Layer
<img width="322" src="https://user-images.githubusercontent.com/5320104/114903196-d7af6f80-9e16-11eb-823c-8ef9e2039ab6.png"></img>
- :hammer_and_wrench: in the **datalayer/functions** folder: create a file for each repository function to be called by the ViewModel's StateReducers
- :hammer_and_wrench: in the **datalayer/objects** folder: create a file for each data class used by the repository functions
- :hammer_and_wrench: in the **datalayer/sources** folder: create a folder for each datasource, where the datasource-specific functions (called by the repository functions) are defined
- :white_check_mark: the **datalayer/Repository.kt** file should be modified only in case you want to add an extra datasource
<br><br>
### PLATFORM-SPECIFIC CODE:
### Android
<img width="352" alt="Schermata 2021-06-26 alle 16 54 32" src="https://user-images.githubusercontent.com/5320104/123515260-f0e65f00-d696-11eb-9ba5-9d44faa58563.png"></img>
<img width="390" alt="Schermata 2021-06-26 alle 17 03 13" src="https://user-images.githubusercontent.com/5320104/123515523-0d36cb80-d698-11eb-9be9-257e1603174d.png"></img>
- :white_check_mark: the **App.kt** file doesn't need to be modified
- :white_check_mark: the **MainActivity.kt** file doesn't need to be modified
- **The composables are used by both Android and Desktop apps:**
- :hammer_and_wrench: the **Level1BottomBar.kt** and **Level1NavigationRail.kt** files in the **navigation/bars** folder should be modified to custom the Navigation bars items
- :white_check_mark: the **TopBar.kt** file in the **navigation/bars** folder doesn't need to be modified
- :white_check_mark: the **OnePane.kt** and **TwoPane.kt** files in the **navigation/templates** folder don't need to be modified
- :white_check_mark: the **HandleBackButton.kt** file in the **navigation** folder doesn't need to be modified
- :white_check_mark: the **Router.kt** file in the **navigation** folder doesn't need to be modified
- :hammer_and_wrench: in the **ScreenPicker.kt** file in the **navigation** folder, you should define the screen composables in your app
- :hammer_and_wrench: in the **screens** folder: create a folder for each screen of the app, containing all composables for that screen
- :white_check_mark: the **MainComposable.kt** file doesn't need to be modified
<br>
### iOS
<img width="307" alt="Schermata 2021-06-26 alle 16 53 55" src="https://user-images.githubusercontent.com/5320104/123515587-496a2c00-d698-11eb-81b9-6fe3174d3c02.png"></img>
- :hammer_and_wrench: the **Level1BottomBar.swift** and **Level1NavigationRail.swift** files in the **composables/navigation/bars** folder should be modified to custom the Navigation bars items
- :white_check_mark: the **TopBar.swift** file in the **composables/navigation/bars** folder doesn't need to be modified
- :white_check_mark: the **OnePane.swift** and **TwoPane.swift** files in the **composables/navigation/templates** folder don't need to be modified
- :white_check_mark: the **Router.swift** file in the **composables/navigation** folder doesn't need to be modified
- :hammer_and_wrench: in the **ScreenPicker.swift** file in the **views/navigation** folder, you should define the screen composables in your app
- :hammer_and_wrench: in the **views/screens** folder: create a folder for each screen of the app, containing all SwiftUI views for that screen
- :white_check_mark: the **MainView.swift** file doesn't need to be modified
- :white_check_mark: the **App.swift** file doesn't need to be modified
- :white_check_mark: the **AppObservableObject.swift** file doesn't need to be modified
<br>
### Desktop
<img width="298" alt="Schermata 2021-06-26 alle 16 54 15" src="https://user-images.githubusercontent.com/5320104/123515803-3efc6200-d699-11eb-9703-4ca4850c89d9.png"></img>
<img width="390" alt="Schermata 2021-06-26 alle 17 03 13" src="https://user-images.githubusercontent.com/5320104/123515523-0d36cb80-d698-11eb-9be9-257e1603174d.png"></img>
- :white_check_mark: the **main.kt** file doesn't need to be modified
- **The composables are used by both Android and Desktop apps:**
- look at the description on the [Android section](#android) above
<br>
### Web (not yet implemented)
没有合适的资源?快使用搜索试试~ 我知道了~
D-KMP-sample.zip
共152个文件
kt:69个
swift:20个
png:16个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 123 浏览量
2024-04-25
00:24:54
上传
评论
收藏 519KB ZIP 举报
温馨提示
kmp算法 KMP算法是什么? 引用自百度百科: KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt提出的,因此人们称它为克努特—莫里斯—普拉特操作(简称KMP算法)。KMP算法的核心是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现就是通过一个next()函数实现,函数本身包含了模式串的局部匹配信息。KMP算法的时间复杂度 也就是说,KMP算法是用来解决字符串匹配问题的,从一个主字符串text中寻找一个子字符串(模式字符串)pattern,看这个子串是否在主串中,比如对于text='abaacababcac'和pattern='ababc',子串是包含在主串中的,同时它在主串中的索引是5。 字符串匹配暴力法 一般的字符串匹配解法是将2个串的字符进行挨个比较,相当于是把每个字符都比较了一遍,这样是一定能得到结果的,不过显然这样操作导致的时间复杂度是 也就是2个字符串的长度之积,俗称暴力解法。
资源推荐
资源详情
资源评论
收起资源包目录
D-KMP-sample.zip (152个子文件)
gradlew.bat 3KB
materialize.min.css 139KB
styles.css 843B
.gitignore 343B
gradlew 6KB
index.html 860B
gradle-wrapper.jar 58KB
materialize.min.js 177KB
sqljs.js 386B
Contents.json 2KB
Contents.json 63B
Contents.json 62B
StateManager.kt 11KB
Navigation.kt 5KB
ScreenIdentifier.kt 3KB
Level1NavigationRail.kt 3KB
Tests.kt 2KB
CountriesListRow.kt 2KB
CountriesListInit.kt 2KB
TwoPane.kt 2KB
ScreenInitSettings.kt 2KB
CountriesListScreen.kt 2KB
CountryDetailScreen.kt 2KB
ApiClient.kt 2KB
ScreenPicker.kt 2KB
CountryDetailState.kt 2KB
GetCountriesList.kt 2KB
Level1BottomBar.kt 2KB
DKMPViewModelForIos.kt 1KB
CountriesListHeader.kt 1KB
CountryDetailInit.kt 1KB
Repository.kt 1KB
App.kt 1KB
GetCountryInfo.kt 1KB
CountriesListState.kt 1KB
Theme.kt 1KB
Router.kt 1KB
NavigationSettings.kt 962B
OnePane.kt 961B
CountryListData.kt 955B
CountriesFunctions.kt 948B
TestUtils.kt 888B
TestUtils.kt 829B
Type.kt 812B
LoadingScreen.kt 801B
TestUtils.kt 796B
CountriesListTwoPaneDefaultDetail.kt 788B
GetFavoriteCountriesMap.kt 781B
ScreenEnum.kt 762B
main.kt 743B
DKMPViewModel.kt 705B
NumberFormats.kt 693B
CountriesListEvents.kt 656B
main.kt 656B
FetchCountryExtraData.kt 612B
TestUtils.kt 610B
StateProvider.kt 609B
DKMPViewModelForDesktop.kt 602B
MainActivity.kt 597B
MySettings.kt 584B
FetchCountriesList.kt 576B
MainComposable.kt 573B
TopBar.kt 504B
CacheObjects.kt 502B
DKMPViewModelForWeb.kt 492B
DKMPViewModelForAndroid.kt 469B
Events.kt 442B
HandleBackButton.kt 363B
TestUtils.kt 347B
Shape.kt 338B
CountryExtraData.kt 314B
Dependencies.kt 290B
HandleBackButton.kt 278B
DebugLogger.kt 250B
Color.kt 230B
DebugLogger.kt 221B
DebugLogger.kt 217B
DebugLogger.kt 217B
HandleBackButton.kt 213B
CountryDetailEvents.kt 141B
DebugLogger.kt 140B
build.gradle.kts 5KB
build.gradle.kts 2KB
build.gradle.kts 1KB
build.gradle.kts 1011B
build.gradle.kts 751B
build.gradle.kts 658B
settings.gradle.kts 330B
build.gradle.kts 106B
LICENSE 11KB
README.md 8KB
README.md 358B
README.md 236B
usingSqlDelight.md 228B
README.md 177B
README.md 168B
project.pbxproj 32KB
Info.plist 2KB
Info.plist 727B
Info.plist 727B
共 152 条
- 1
- 2
资源评论
野生的狒狒
- 粉丝: 1918
- 资源: 1884
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功