Skip to content

Commit

Permalink
Reduce app resources using collectAsStateWithLifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeso committed Mar 22, 2024
1 parent f94e478 commit 9f9ea3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.ui.tooling.preview)
debugImplementation(libs.androidx.ui.tooling)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/net/leodesouza/blitz/ui/ChessClockScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -64,6 +63,7 @@ import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ fun ChessClockScreen(
ChessClockViewModel(durationMinutes, incrementSeconds, tickPeriod)
},
) {
val uiState by clock.uiState.collectAsState()
val uiState by clock.uiState.collectAsStateWithLifecycle()
val lifecycleOwner = LocalLifecycleOwner.current
val context = LocalContext.current
val isLandscape = LocalConfiguration.current.orientation == ORIENTATION_LANDSCAPE
Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
agp = "8.3.1"
java = "17"
kotlin = "1.9.23"
activityCompose = "1.8.2"
activity = "1.8.2"
composeBom = "2024.03.00"
composeCompiler = "1.5.11"
lifecycleViewmodelCompose = "2.7.0"
lifecycle = "2.7.0"

[libraries]
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycle" }
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }

Expand Down

0 comments on commit 9f9ea3e

Please sign in to comment.