File tree Expand file tree Collapse file tree
Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1314,11 +1314,19 @@ private fun RenderAsyncImage(node: ViewNode) {
13141314 Text (" [image]" , modifier = node.composeModifiers())
13151315 return
13161316 }
1317- var bitmap by remember(url) { mutableStateOf<ImageBitmap ?>(null ) }
1317+ // Seed from the cache synchronously: a URL already fetched renders on the
1318+ // first frame with no spinner. Only a miss touches the network.
1319+ var bitmap by remember(url) { mutableStateOf(ImageCache .get(url)) }
13181320 var failed by remember(url) { mutableStateOf(false ) }
13191321 LaunchedEffect (url) {
1322+ if (bitmap != null ) return @LaunchedEffect
13201323 val loaded = loadRemoteImage(url)
1321- if (loaded != null ) bitmap = loaded else failed = true
1324+ if (loaded != null ) {
1325+ ImageCache .put(url, loaded)
1326+ bitmap = loaded
1327+ } else {
1328+ failed = true
1329+ }
13221330 }
13231331 val image = bitmap
13241332 when {
You can’t perform that action at this time.
0 commit comments