admin管理员组

文章数量:1300203

I'm loading the same image (from the netowrk) on different ASyncImage composables: one is "full screen" and it's blurred, the other is on top and represent the sharp version of the image. Sometimes the image loading don't take place at the same time leading to a poor UX.

Here is the code:

@Composable
fun BlurredAsyncImage(
    url: String,
    imageLoader: ImageLoader,
    blurRadius: Dp = 50.dp
) {
    Box(
        modifier = Modifier
            .fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        // blurred image as background
        AsyncImage(
            imageLoader = imageLoader,
            model = buildImageRequest(
                itemId = itemId,
                url = url
            ),
            contentScale = ContentScale.Crop,
            modifier = Modifier
                .fillMaxWidth()
                .blur(blurRadius)
        )
        // sharp image as foreground
        AsyncImage(
            imageLoader = imageLoader,
            model = buildImageRequest(
                itemId = itemId,
                url = url
            ),
            contentScale = ContentScale.Fit,
            modifier = Modifier
                .fillMaxWidth()
        )
    }
}    


@Composable
private fun buildImageRequest(
    itemId: Long,
    url: String
) = ImageRequest.Builder(LocalContext.current)
    .data(url)
    .build()

Do you have any hint on how I can make them appear simultaneously?

本文标签: androidHow to synchronize images loading with Coil3Stack Overflow