Skip to content

Commit d7b25fc

Browse files
committed
Improve the recomposition problem for the palette
1 parent dff20d4 commit d7b25fc

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ android {
5656
"DebugProbesKt.bin",
5757
"kotlin-tooling-metadata.json",
5858
"kotlin/**",
59-
"META-INF/*.version"
6059
)
6160
}
6261
}

feature/details/src/main/kotlin/com/skydoves/pokedex/compose/feature/details/PokedexDetails.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.skydoves.pokedex.compose.feature.details
1818

1919
import android.content.res.Configuration
20+
import android.util.Log
2021
import androidx.compose.animation.AnimatedVisibilityScope
2122
import androidx.compose.animation.SharedTransitionScope
2223
import androidx.compose.foundation.background
@@ -44,6 +45,8 @@ import androidx.compose.runtime.setValue
4445
import androidx.compose.ui.Alignment
4546
import androidx.compose.ui.Modifier
4647
import androidx.compose.ui.draw.shadow
48+
import androidx.compose.ui.graphics.Brush
49+
import androidx.compose.ui.graphics.Color
4750
import androidx.compose.ui.layout.ContentScale
4851
import androidx.compose.ui.platform.LocalInspectionMode
4952
import androidx.compose.ui.platform.testTag
@@ -63,6 +66,7 @@ import com.skydoves.landscapist.animation.crossfade.CrossfadePlugin
6366
import com.skydoves.landscapist.components.rememberImageComponent
6467
import com.skydoves.landscapist.glide.GlideImage
6568
import com.skydoves.landscapist.palette.PalettePlugin
69+
import com.skydoves.landscapist.palette.rememberPaletteState
6670
import com.skydoves.pokedex.compose.core.data.repository.details.FakeDetailsRepository
6771
import com.skydoves.pokedex.compose.core.designsystem.component.PokedexCircularProgress
6872
import com.skydoves.pokedex.compose.core.designsystem.component.PokedexText
@@ -92,10 +96,16 @@ fun SharedTransitionScope.PokedexDetails(
9296
.verticalScroll(rememberScrollState())
9397
.testTag("PokedexDetails"),
9498
) {
99+
100+
var palette by rememberPaletteState()
101+
val backgroundBrush by palette.paletteBackgroundBrush()
102+
95103
DetailsHeader(
96104
animatedVisibilityScope = animatedVisibilityScope,
97105
pokemon = pokemon,
98106
pokemonInfo = pokemonInfo,
107+
onPaletteLoaded = { palette = it },
108+
backgroundBrush = backgroundBrush
99109
)
100110

101111
if (uiState == DetailsUiState.Idle && pokemonInfo != null) {
@@ -115,18 +125,17 @@ private fun SharedTransitionScope.DetailsHeader(
115125
animatedVisibilityScope: AnimatedVisibilityScope,
116126
pokemon: Pokemon?,
117127
pokemonInfo: PokemonInfo?,
128+
onPaletteLoaded: (Palette) -> Unit,
129+
backgroundBrush: Brush,
118130
) {
119131
val composeNavigator = currentComposeNavigator
120-
var palette by remember { mutableStateOf<Palette?>(null) }
121132
val shape = RoundedCornerShape(
122133
topStart = 0.dp,
123134
topEnd = 0.dp,
124135
bottomStart = 64.dp,
125136
bottomEnd = 64.dp,
126137
)
127138

128-
val backgroundBrush by palette.paletteBackgroundBrush()
129-
130139
Box(
131140
modifier = Modifier
132141
.fillMaxWidth()
@@ -135,7 +144,9 @@ private fun SharedTransitionScope.DetailsHeader(
135144
.background(brush = backgroundBrush, shape = shape),
136145
) {
137146
Row(
138-
modifier = Modifier.padding(12.dp).statusBarsPadding(),
147+
modifier = Modifier
148+
.padding(12.dp)
149+
.statusBarsPadding(),
139150
verticalAlignment = Alignment.CenterVertically,
140151
) {
141152
Icon(
@@ -188,7 +199,7 @@ private fun SharedTransitionScope.DetailsHeader(
188199
+PalettePlugin(
189200
imageModel = pokemon?.imageUrl,
190201
useCache = true,
191-
paletteLoadedListener = { palette = it },
202+
paletteLoadedListener = { onPaletteLoaded.invoke(it) },
192203
)
193204
}
194205
},

feature/home/src/main/kotlin/com/skydoves/pokedex/compose/feature/home/PokedexHome.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.skydoves.pokedex.compose.feature.home
1818

1919
import android.content.res.Configuration
20+
import android.util.Log
2021
import androidx.compose.animation.AnimatedVisibility
2122
import androidx.compose.animation.AnimatedVisibilityScope
2223
import androidx.compose.animation.SharedTransitionScope

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
agp = "8.7.3"
33
kotlin = "2.1.0"
4-
ksp = "2.0.21-1.0.28"
4+
ksp = "2.1.0-1.0.29"
55
kotlinxImmutable = "0.3.7"
66
androidxActivity = "1.9.3"
77
androidxCore = "1.15.0"

0 commit comments

Comments
 (0)