Skip to content

Commit fb85817

Browse files
authored
Add KMP ViewModel snippets (#611)
* Add kotlin gitignore * Add KMP shared module * Add xcode gitignore * Add kmp ios app * Add KMP ViewModel * Fix ios build * Add viewmodel snippet * Move to directory * Move kmp to :shared * Add KMP regions * Add swift content * Add comments with file path * Add build-ios workflow * Fix concurrency * Apply Spotless --------- Co-authored-by: mlykotom <[email protected]>
1 parent 6301d76 commit fb85817

File tree

23 files changed

+882
-11
lines changed

23 files changed

+882
-11
lines changed

.github/workflows/build-ios.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: Build snippets
15+
16+
on:
17+
push:
18+
branches: [ '*' ]
19+
paths:
20+
- 'kmp/**'
21+
- '.github/workflows/build-ios.yml'
22+
pull_request:
23+
branches: [ '*' ]
24+
paths:
25+
- 'kmp/**'
26+
- '.github/workflows/build-ios.yml'
27+
workflow_dispatch:
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.ref }}-build-ios
30+
cancel-in-progress: true
31+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
32+
jobs:
33+
build_ios:
34+
name: Build iOS app
35+
runs-on: macos-latest
36+
steps:
37+
- uses: maxim-lobanov/setup-xcode@v1
38+
with:
39+
xcode-version: latest-stable
40+
41+
- name: Checkout
42+
uses: actions/checkout@v5
43+
44+
- name: Build iOS app
45+
uses: mxcl/xcodebuild@v3
46+
with:
47+
xcode: ^16
48+
scheme: iosApp
49+
platform: iOS
50+
action: build
51+
working-directory: kmp/iosApp

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ build
1111
.externalNativeBuild
1212
.idea/*
1313
/.idea/*
14+
.kotlin
15+
16+
### Xcode ###
17+
## User settings
18+
xcuserdata/
19+
20+
### Xcode Patch ###
21+
*.xcodeproj/*
22+
!*.xcodeproj/project.pbxproj
23+
!*.xcodeproj/xcshareddata/
24+
!*.xcodeproj/project.xcworkspace/
25+
!*.xcworkspace/contents.xcworkspacedata
26+
/*.gcno
27+
**/xcshareddata/WorkspaceSettings.xcsettings

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ plugins {
1010
alias(libs.plugins.kotlin.parcelize) apply false
1111
alias(libs.plugins.compose.compiler) apply false
1212
alias(libs.plugins.kotlin.serialization) apply false
13+
alias(libs.plugins.kotlin.multiplatform) apply false
14+
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
15+
alias(libs.plugins.android.lint) apply false
1316
}
1417

1518
apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

gradle/libs.versions.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-kt
130130
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle-runtime-compose" }
131131
androidx-lifecycle-service = { module = "androidx.lifecycle:lifecycle-service", version.ref = "lifecycleService" }
132132
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-compose" }
133+
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "androidx-lifecycle-compose" }
133134
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
134135
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
135136
androidx-media3-common = { module = "androidx.media3:media3-common", version.ref = "media3" }
@@ -179,7 +180,7 @@ horologist-compose-layout = { module = "com.google.android.horologist:horologist
179180
horologist-compose-material = { module = "com.google.android.horologist:horologist-compose-material", version.ref = "horologist" }
180181
junit = { module = "junit:junit", version.ref = "junit" }
181182
kotlin-coroutines-okhttp = { module = "ru.gildor.coroutines:kotlin-coroutines-okhttp", version.ref = "kotlinCoroutinesOkhttp" }
182-
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
183+
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
183184
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
184185
kotlinx-coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava", version.ref = "kotlinxCoroutinesGuava" }
185186
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
@@ -189,6 +190,8 @@ play-services-wearable = { module = "com.google.android.gms:play-services-wearab
189190
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
190191
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
191192
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }
193+
jetbrains-kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
194+
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
192195

193196
[plugins]
194197
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
@@ -197,7 +200,10 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "
197200
gradle-versions = { id = "com.github.ben-manes.versions", version.ref = "gradle-versions" }
198201
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
199202
kotlin-android = "org.jetbrains.kotlin.android:2.2.10"
203+
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
204+
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "androidGradlePlugin" }
200205
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
201206
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
202207
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
203208
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
209+
android-lint = { id = "com.android.lint", version.ref = "androidGradlePlugin" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TEAM_ID=
2+
3+
PRODUCT_NAME=KotlinProject
4+
PRODUCT_BUNDLE_IDENTIFIER=org.example.project.KotlinProject$(TEAM_ID)
5+
6+
CURRENT_PROJECT_VERSION=1
7+
MARKETING_VERSION=1.0

0 commit comments

Comments
 (0)