From aa5c8a703db4460d1ddaf9431c8c268b2bcac51d Mon Sep 17 00:00:00 2001 From: todayama_r <13657682+Corvus400@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:24:54 +0900 Subject: [PATCH 1/3] :wrench: The problem of flickering icons has been addressed by caching ImageRequests. Every time you scroll, a new ImageRequest instance was created using LocalContext.current. As a result, rememberAsyncImagePainter would create a new Painter each time, causing flickering when scrolling. --- .../component/SpeakerPainter.android.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/droidkaigiui/src/androidMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/component/SpeakerPainter.android.kt b/core/droidkaigiui/src/androidMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/component/SpeakerPainter.android.kt index fe9517d46..c7c2981fe 100644 --- a/core/droidkaigiui/src/androidMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/component/SpeakerPainter.android.kt +++ b/core/droidkaigiui/src/androidMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/component/SpeakerPainter.android.kt @@ -1,6 +1,7 @@ package io.github.droidkaigi.confsched.droidkaigiui.component import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.platform.LocalContext import coil3.request.ImageRequest @@ -10,13 +11,17 @@ import io.github.droidkaigi.confsched.droidkaigiui.rememberAsyncImagePainter @Composable actual fun speakerPainter(url: String): Painter { - // TODO Use DrawableResource - // https://github.com/DroidKaigi/conference-app-2024/pull/864/files#r1736437080 - // https://github.com/coil-kt/coil/issues/2077 - return rememberAsyncImagePainter( - model = ImageRequest.Builder(LocalContext.current) + val context = LocalContext.current + + val imageRequest = remember(url, context) { + // TODO Use DrawableResource + // https://github.com/DroidKaigi/conference-app-2024/pull/864/files#r1736437080 + // https://github.com/coil-kt/coil/issues/2077 + ImageRequest.Builder(context) .data(url) .placeholder(R.drawable.icon_place_hoolder) - .build(), - ) + .build() + } + + return rememberAsyncImagePainter(model = imageRequest) } From ddac0d0e16b02562af5bf79540fcfb8b82e3b05b Mon Sep 17 00:00:00 2001 From: todayama_r <13657682+Corvus400@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:31:42 +0900 Subject: [PATCH 2/3] :wrench: The same response was needed for rememberAsyncImagePainter, so it was implemented. --- .../github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt b/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt index ee7784eb8..90e85dd69 100644 --- a/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt +++ b/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt @@ -1,6 +1,7 @@ package io.github.droidkaigi.confsched.droidkaigiui import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.graphics.painter.Painter import coil3.request.ImageRequest @@ -13,7 +14,9 @@ fun rememberAsyncImagePainter(url: String): Painter { @Composable fun rememberAsyncImagePainter(model: ImageRequest): Painter { + val requestModel = remember(model) { model } + return coil3.compose.rememberAsyncImagePainter( - model = model, + model = requestModel ) } From 07ab2e9d120fedb248150049bde4cb4ce586ae02 Mon Sep 17 00:00:00 2001 From: todayama_r <13657682+Corvus400@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:31:59 +0900 Subject: [PATCH 3/3] :wrench: ./gradlew detekt --auto-correct --- .../io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt b/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt index 90e85dd69..eb085d6f3 100644 --- a/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt +++ b/core/droidkaigiui/src/commonMain/kotlin/io/github/droidkaigi/confsched/droidkaigiui/ImagePainter.kt @@ -17,6 +17,6 @@ fun rememberAsyncImagePainter(model: ImageRequest): Painter { val requestModel = remember(model) { model } return coil3.compose.rememberAsyncImagePainter( - model = requestModel + model = requestModel, ) }