From c0fe6831c7b4e7ad207fc63667586da5bf5b0d51 Mon Sep 17 00:00:00 2001 From: hehua2008 Date: Wed, 3 Jan 2024 15:07:04 +0800 Subject: [PATCH] Fix the bug that AsyncImage demo cannot update new images "val image: T? by produceState()" should use "load" as a key, or else it won't be re-launched for the new "load". And "painterFor = { remember { BitmapPainter(it) } }" should use "it" as a key for the "remember", or else the "painterFor" won't update for the new "image" loaded by "produceState". --- tutorials/Image_And_Icons_Manipulations/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/Image_And_Icons_Manipulations/README.md b/tutorials/Image_And_Icons_Manipulations/README.md index 70c64eb15e1..1eadb31f01a 100755 --- a/tutorials/Image_And_Icons_Manipulations/README.md +++ b/tutorials/Image_And_Icons_Manipulations/README.md @@ -68,7 +68,7 @@ fun main() = singleWindowApplication { Column { AsyncImage( load = { loadImageBitmap(File("sample.png")) }, - painterFor = { remember { BitmapPainter(it) } }, + painterFor = { remember(it) { BitmapPainter(it) } }, contentDescription = "Sample", modifier = Modifier.width(200.dp) ) @@ -97,7 +97,7 @@ fun AsyncImage( modifier: Modifier = Modifier, contentScale: ContentScale = ContentScale.Fit, ) { - val image: T? by produceState(null) { + val image: T? by produceState(null, load) { value = withContext(Dispatchers.IO) { try { load()