Awesome-android-agent-skills coil-compose
Expert guidance on using Coil for image loading in Jetpack Compose. Use this when asked about loading images from URLs, handling image states, or optimizing image performance in Compose.
install
source · Clone the upstream repo
git clone https://github.com/new-silvermoon/awesome-android-agent-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/new-silvermoon/awesome-android-agent-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.github/skills/ui/coil-compose" ~/.claude/skills/new-silvermoon-awesome-android-agent-skills-coil-compose && rm -rf "$T"
manifest:
.github/skills/ui/coil-compose/SKILL.mdsource content
Coil for Jetpack Compose
Instructions
When implementing image loading in Jetpack Compose, use Coil (Coroutines Image Loader). It is the recommended library for Compose due to its efficiency and seamless integration.
1. Primary Composable: AsyncImage
AsyncImageUse
AsyncImage for most use cases. It handles size resolution automatically and supports standard Image parameters.
AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data("https://example.com/image.jpg") .crossfade(true) .build(), placeholder = painterResource(R.drawable.placeholder), error = painterResource(R.drawable.error), contentDescription = stringResource(R.string.description), contentScale = ContentScale.Crop, modifier = Modifier.clip(CircleShape) )
2. Low-Level Control: rememberAsyncImagePainter
rememberAsyncImagePainterUse
rememberAsyncImagePainter only when you need a Painter instead of a composable (e.g., for Canvas or Icon) or when you need to observe the loading state manually.
[!WARNING]
does not detect the size your image is loaded at on screen and always loads the image with its original dimensions by default. UserememberAsyncImagePainterunless aAsyncImageis strictly required.Painter
val painter = rememberAsyncImagePainter( model = ImageRequest.Builder(LocalContext.current) .data("https://example.com/image.jpg") .size(Size.ORIGINAL) // Explicitly define size if needed .build() )
3. Slot API: SubcomposeAsyncImage
SubcomposeAsyncImageUse
SubcomposeAsyncImage when you need a custom slot API for different states (Loading, Success, Error).
[!CAUTION] Subcomposition is slower than regular composition. Avoid using
in performance-critical areas likeSubcomposeAsyncImageorLazyColumn.LazyRow
SubcomposeAsyncImage( model = "https://example.com/image.jpg", contentDescription = null, loading = { CircularProgressIndicator() }, error = { Icon(Icons.Default.Error, contentDescription = null) } )
4. Performance & Best Practices
- Singleton ImageLoader: Use a single
instance for the entire app to share the disk/memory cache.ImageLoader - Main-Safe: Coil executes image requests on a background thread automatically.
- Crossfade: Always enable
incrossfade(true)
for a smoother transition from placeholder to success.ImageRequest - Sizing: Ensure
is set appropriately to avoid loading larger images than necessary.contentScale
5. Checklist for implementation
- Prefer
over other variants.AsyncImage - Always provide a meaningful
or set it tocontentDescription
for decorative images.null - Use
for better UX.crossfade(true) - Avoid
in lists.SubcomposeAsyncImage - Configure
for specific needs like transformations (e.g.,ImageRequest
).CircleCropTransformation