Skip to content

Commit 688edf4

Browse files
committed
Add viewmodel screen for KMP
1 parent e4396f6 commit 688edf4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

kmp/shared/build.gradle.kts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ kotlin {
6464

6565
androidMain {
6666
dependencies {
67-
// Add Android-specific dependencies here. Note that this source set depends on
68-
// commonMain by default and will correctly pull the Android artifacts of any KMP
69-
// dependencies declared in commonMain.
67+
val composeBom = project.dependencies.platform(libs.androidx.compose.bom)
68+
implementation(composeBom)
69+
implementation(libs.androidx.compose.runtime)
70+
implementation(libs.androidx.compose.foundation)
71+
implementation(libs.androidx.compose.foundation.layout)
72+
implementation(libs.androidx.compose.ui.util)
73+
implementation(libs.androidx.compose.material)
74+
implementation(libs.androidx.lifecycle.runtime)
75+
implementation(libs.androidx.lifecycle.viewModelCompose)
7076
}
7177
}
7278

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.kmp.snippets
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.lifecycle.viewmodel.compose.viewModel
5+
6+
7+
// [START android_kmp_viewmodel_screen]
8+
// androidApp/ui/MainScreen.kt
9+
10+
@Composable
11+
fun MainScreen(
12+
viewModel: MainViewModel = viewModel(
13+
factory = mainViewModelFactory,
14+
),
15+
) {
16+
// observe the viewModel state
17+
}
18+
// [END android_kmp_viewmodel_screen]

0 commit comments

Comments
 (0)