From bcc38f7b596ee27164ea1281426509d94e9e16a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Sun, 12 May 2024 16:36:15 -0700 Subject: [PATCH 1/2] Simplify Constraints creation --- .../compose/performance/phases/PhasesAnimatedShape.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PerformanceCodelab/app/src/main/java/com/compose/performance/phases/PhasesAnimatedShape.kt b/PerformanceCodelab/app/src/main/java/com/compose/performance/phases/PhasesAnimatedShape.kt index 1ce218bf8..5310c67c7 100644 --- a/PerformanceCodelab/app/src/main/java/com/compose/performance/phases/PhasesAnimatedShape.kt +++ b/PerformanceCodelab/app/src/main/java/com/compose/performance/phases/PhasesAnimatedShape.kt @@ -79,12 +79,12 @@ fun MyShape(size: () -> Dp, modifier: Modifier = Modifier) = trace("MyShape") { val sizePx = size() .roundToPx() .coerceAtLeast(0) - val constraints = Constraints( - minWidth = sizePx, - maxWidth = sizePx, - minHeight = sizePx, - maxHeight = sizePx + + val constraints = Constraints.fixed( + width = sizePx, + height = sizePx, ) + val placeable = measurable.measure(constraints) layout(sizePx, sizePx) { placeable.place(0, 0) From bb8cdbc7c5775293dad8af797a4aaf2e80fa60b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Tue, 14 May 2024 07:07:09 -0700 Subject: [PATCH 2/2] Add stability task end state --- PerformanceCodelab/app/build.gradle.kts | 3 ++- .../com/compose/performance/stability/StabilityViewModel.kt | 2 ++ PerformanceCodelab/stability_config.conf | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/PerformanceCodelab/app/build.gradle.kts b/PerformanceCodelab/app/build.gradle.kts index b1ba4c99d..18ba60b03 100644 --- a/PerformanceCodelab/app/build.gradle.kts +++ b/PerformanceCodelab/app/build.gradle.kts @@ -69,9 +69,10 @@ composeCompiler { // This settings enables strong-skipping mode for all module in this project. // As an effect, Compose can skip a composable even if it's unstable by comparing it's instance equality (===). // TODO Codelab task: Enable Strong Skipping Mode - enableStrongSkippingMode = false + enableStrongSkippingMode = true // TODO Codelab task: Enable Stability Configuration file + stabilityConfigurationFile = project.rootDir.resolve("stability_config.conf") } dependencies { diff --git a/PerformanceCodelab/app/src/main/java/com/compose/performance/stability/StabilityViewModel.kt b/PerformanceCodelab/app/src/main/java/com/compose/performance/stability/StabilityViewModel.kt index 2adef7aba..76e690192 100644 --- a/PerformanceCodelab/app/src/main/java/com/compose/performance/stability/StabilityViewModel.kt +++ b/PerformanceCodelab/app/src/main/java/com/compose/performance/stability/StabilityViewModel.kt @@ -15,6 +15,7 @@ */ package com.compose.performance.stability +import androidx.compose.runtime.Immutable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.neverEqualPolicy @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn // TODO Codelab task: make this class Stable +@Immutable data class StabilityItem( val id: Int, val type: StabilityItemType, diff --git a/PerformanceCodelab/stability_config.conf b/PerformanceCodelab/stability_config.conf index 68fd0b7fe..5f96adb3f 100644 --- a/PerformanceCodelab/stability_config.conf +++ b/PerformanceCodelab/stability_config.conf @@ -1 +1,3 @@ // TODO Codelab task: Make a java.time.LocalDate class stable. + +java.time.LocalDate