Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions kmp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ kotlin {

androidMain {
dependencies {
// Add Android-specific dependencies here. Note that this source set depends on
// commonMain by default and will correctly pull the Android artifacts of any KMP
// dependencies declared in commonMain.
val composeBom = project.dependencies.platform(libs.androidx.compose.bom)
implementation(composeBom)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.foundation.layout)
implementation(libs.androidx.compose.ui.util)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.viewModelCompose)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.kmp.snippets

import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel

// [START android_kmp_viewmodel_screen]
// androidApp/ui/MainScreen.kt

@Composable
fun MainScreen(
viewModel: MainViewModel = viewModel(
factory = mainViewModelFactory,
),
) {
// observe the viewModel state
}
// [END android_kmp_viewmodel_screen]
Loading