AsyncPic
The main composable. Handles all image loading, transitions, effects, and callbacks.
@Composable
fun AsyncPic(
source: ImageSource,
modifier: Modifier = Modifier,
contentDescription: String? = null,
shape: Shape = RectangleShape,
placeholderUrl: String? = null,
blurRadius: Int = 0,
circleCrop: Boolean = false,
placeholder: @Composable () -> Unit = { DefaultShimmer() },
placeholderType: ImageSource.PlaceholderType = ImageSource.PlaceholderType.SHIMMER,
shimmerColor: Color = Color(0xFFF1F5F9),
shimmerDirection: ImageSource.ShimmerDirection = ImageSource.ShimmerDirection.DIAGONAL,
error: @Composable () -> Unit = { DefaultError() },
zoomable: Boolean = false,
minShimmerTime: Long = 1000,
contentScale: ContentScale = ContentScale.Crop,
diskCachePolicy: CachePolicy = CachePolicy.ENABLED,
memoryCachePolicy: CachePolicy = CachePolicy.ENABLED,
onPaletteLoaded: ((AsyncPicPalette) -> Unit)? = null,
onSuccess: (() -> Unit)? = null,
onError: ((Throwable) -> Unit)? = null,
parallaxIntensity: Float = 0f,
transition: AsyncPicTransition = AsyncPicTransition.Standard
)
Parametersâ
sourceâ
ImageSource â Required
The image source. One of:
ImageSource.Url(value: String)â load from URLImageSource.Resources(resId: Int)â load from drawable resourceImageSource.Progressive(finalUrl, thumbnailUrl?, blurHash?)â progressive loading
modifierâ
Modifier = Modifier
Standard Compose modifier applied to the outer Box.
contentDescriptionâ
String? = null
Accessibility description for screen readers.
shapeâ
Shape = RectangleShape
Clips the image to any shape. Common values: RoundedCornerShape(16.dp), CircleShape.
Shape clipping is applied to the outer Box. When zoomable = true, clipping is deferred to the graphics layer to allow correct pan behavior.
placeholderUrlâ
String? = null
A Coil memory cache key for a pre-loaded placeholder image. Useful if you already have a smaller version in the cache.
blurRadiusâ
Int = 0
Applies CustomBlurTransformation using RenderScript. Range: 0â25. On ImageSource.Progressive, this is applied to the thumbnail layer.
circleCropâ
Boolean = false
Applies Coil's CircleCropTransformation. Alternative to shape = CircleShape â handled at the bitmap level.
placeholderâ
@Composable () -> Unit = { DefaultShimmer() }
Custom placeholder composable shown while loading. Overrides placeholderType if supplied.
placeholderTypeâ
ImageSource.PlaceholderType = SHIMMER
Built-in placeholder style:
| Value | Description |
|---|---|
SHIMMER | Animated gradient shimmer (default) |
SKELETON | Pulsing opacity block |
NONE | Nothing shown while loading |
shimmerColorâ
Color = Color(0xFFF1F5F9)
Base color for the shimmer gradient. AsyncPic will animate this toward the image's dominant color once loaded (Adaptive Color Morphing).
shimmerDirectionâ
ImageSource.ShimmerDirection = DIAGONAL
Direction of the shimmer sweep: DIAGONAL, LTR, RTL, TTB, BTT.
errorâ
@Composable () -> Unit = { DefaultError() }
Composable shown when image fails to load. Default shows a warning icon.
zoomableâ
Boolean = false
Enables pinch-to-zoom (1xâ4x) and double-tap toggle (1x â 3x).
minShimmerTimeâ
Long = 1000
Minimum time in milliseconds to show the shimmer/placeholder, even if the image loads faster. Skipped for animated formats (GIF/WebP).
contentScaleâ
ContentScale = ContentScale.Crop
How the image is scaled to fit its bounds. Standard Compose ContentScale values.
diskCachePolicyâ
CachePolicy = CachePolicy.ENABLED
Controls Coil disk caching for this image.
memoryCachePolicyâ
CachePolicy = CachePolicy.ENABLED
Controls Coil memory caching for this image.
onPaletteLoadedâ
((AsyncPicPalette) -> Unit)? = null
Called after a successful load with 5 extracted color swatches. Called on the main thread via Palette's async generator.
onSuccessâ
(() -> Unit)? = null
Called when the image loads successfully.
onErrorâ
((Throwable) -> Unit)? = null
Called when the image fails to load, with the underlying exception.
parallaxIntensityâ
Float = 0f
Applies a scroll-based parallax offset. 0f disables it. Recommended range: 0.02fâ0.08f.
transitionâ
AsyncPicTransition = AsyncPicTransition.Standard
The reveal animation when the image finishes loading:
AsyncPicTransition.Standardâ Coil's default crossfadeAsyncPicTransition.ShaderReveal(type, durationMillis)â AGSL shader (Android 13+)