Skip to content

Commit 3ba98bb

Browse files
Merge pull request #400 from android/fm/m3_withlifecycle
[Theming][End] Using collectAsStateWithLifecycle
2 parents f9d4c21 + ec6b0c5 commit 3ba98bb

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

ThemingCodelab/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121

2222
android {
2323
namespace "com.example.reply"
24-
compileSdkVersion 34
24+
compileSdk 34
2525
defaultConfig {
2626
applicationId 'com.example.reply'
2727
minSdkVersion 21
@@ -117,6 +117,7 @@ dependencies {
117117
implementation 'androidx.core:core-ktx:1.12.0'
118118
implementation "androidx.activity:activity-compose:1.8.1"
119119

120+
implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.2"
120121
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
121122
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2"
122123
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.2"

ThemingCodelab/app/src/main/java/com/example/reply/ui/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.runtime.collectAsState
2727
import androidx.compose.runtime.getValue
2828
import androidx.compose.ui.tooling.preview.Preview
2929
import androidx.compose.ui.unit.dp
30+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3031
import com.example.reply.data.LocalEmailsDataProvider
3132
import com.example.reply.ui.theme.AppTheme
3233

@@ -38,7 +39,7 @@ class MainActivity : ComponentActivity() {
3839

3940
setContent {
4041

41-
val uiState by viewModel.uiState.collectAsState()
42+
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
4243

4344
AppTheme {
4445
Surface(tonalElevation = 5.dp) {

0 commit comments

Comments
 (0)