Coil v2.0.0-alpha04 Release Notes

Release Date: 2021-11-22 // over 2 years ago
    • 🆕 New: Add AsyncImage to coil-compose.
      • AsyncImage is a composable that executes an ImageRequest asynchronously and renders the result.
      • AsyncImage is intended to replace rememberImagePainter for most use cases.
      • Its API is not final and may change before the final 2.0 release.
      • It has a similar API to Image and supports the same arguments: Alignment, ContentScale, alpha, ColorFilter, and FilterQuality.
      • It supports overwriting what's drawn for each AsyncImagePainter state using the content, loading, success, and error arguments.
      • It fixes a number of design issues that rememberImagePainter has with resolving image size and scale.
      • Example usages:
    // Only draw the image.
    AsyncImage(
        model = "https://example.com/image.jpg",
        contentDescription = null // Avoid `null` and set this to a localized string if possible.
    )
    
    // Draw the image with a circle crop, crossfade, and overwrite the `loading` state.
    AsyncImage(
        model = ImageRequest.Builder(LocalContext.current)
            .data("https://example.com/image.jpg")
            .crossfade(true)
            .build(),
        contentDescription = null,
        modifier = Modifier
            .clip(CircleShape),
        loading = {
            CircularProgressIndicator()
        },
        contentScale = ContentScale.Crop
    )
    
    // Draw the image with a circle crop, crossfade, and overwrite all states.
    AsyncImage(
        model = ImageRequest.Builder(LocalContext.current)
            .data("https://example.com/image.jpg")
            .crossfade(true)
            .build(),
        contentDescription = null,
        modifier = Modifier
            .clip(CircleShape),
        contentScale = ContentScale.Crop
    ) { state ->
        if (state is AsyncImagePainter.State.Loading) {
            CircularProgressIndicator()
        } else {
            AsyncImageContent() // Draws the image.
        }
    }
    
    • Important: Rename ImagePainter to AsyncImagePainter and rememberImagePainter to rememberAsyncImagePainter.
      • ExecuteCallback is no longer supported. To have the AsyncImagePainter skip waiting for onDraw to be called, set ImageRequest.size(OriginalSize) (or any size) instead.
      • Add an optional FilterQuality argument to rememberAsyncImagePainter.
    • 🏗 Use coroutines for cleanup operations in DiskCache and add DiskCache.Builder.cleanupDispatcher.
    • 🛠 Fix Compose preview for placeholder set using ImageLoader.Builder.placeholder.
    • Mark LocalImageLoader.current with @ReadOnlyComposable to generate more efficient code.
    • ⚡️ Update Compose to 1.1.0-beta03 and depend on compose.foundation instead of compose.ui.
    • ⚡️ Update androidx.appcompat-resources to 1.4.0.