android-image-loading-coillisted
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android Image Loading with Coil
## Core Principles
- Load images with explicit sizing whenever possible.
- Treat image loading as UI infrastructure, not business logic.
- Prefer simple loading pipelines before adding transformations.
- Keep loading/error UI states intentional.
- Optimize for scrolling performance on image-heavy screens.
---
## Default Compose Usage
For most screens, use Coil's Compose integration:
```kotlin
AsyncImage(
model = imageUrl,
contentDescription = stringResource(R.string.cd_profile_photo),
modifier = Modifier.size(64.dp),
contentScale = ContentScale.Crop
)
```
This is appropriate for:
- avatars
- thumbnails
- banners
- article/product images
---
## Prefer Explicit Image Requests When Needed
Use `ImageRequest` when behavior should be controlled more precisely:
```kotlin
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.crossfade(true)
.build(),
contentDescription = stringResource(R.string.cd_cover_image)
)
```
Good reasons to use `ImageRequest`:
- enable crossfade
- specify placeholders or error drawables
- set size or transformations
- add headers or special cache behavior
---
## Loading and Error States
Screens should define what happens when an image:
- is loading
- fails to load
- is absent entirely
Typical options:
- placeholder while loading
- fallback avatar/icon when missing
- stable error UI when request fails
Avoid blank flashing regions when im