Placeholders & Shimmer
AsyncPic provides three built-in placeholder types, controlled by placeholderType.
PlaceholderType​
enum class PlaceholderType {
SHIMMER, // Animated shimmer gradient (default)
SKELETON, // Pulsing solid block
NONE // No placeholder at all
}
Shimmer (Default)​
The default shimmer animates a gradient across the image area while loading.
AsyncPic(
source = ImageSource.Url("https://example.com/photo.jpg"),
modifier = Modifier.size(200.dp),
placeholderType = ImageSource.PlaceholderType.SHIMMER
)
Shimmer Color​
Customize the base shimmer color:
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
shimmerColor = Color(0xFFE2E8F0) // default slate-200
)
🌈 Adaptive Color Morphing​
One of AsyncPic's unique features — the shimmer automatically extracts the dominant color of the loaded image and smoothly transitions the shimmer into that color before the image appears.
This happens automatically! No extra code needed.
Shimmer Directions​
5 directions supported via shimmerDirection:
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
shimmerDirection = ImageSource.ShimmerDirection.LTR // left to right
)
| Direction | Description |
|---|---|
DIAGONAL | Top-left to bottom-right (default) |
LTR | Left to right |
RTL | Right to left |
TTB | Top to bottom |
BTT | Bottom to top |
Skeleton​
A pulsing opacity animation — great for card/list layouts:
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
placeholderType = ImageSource.PlaceholderType.SKELETON
)
No Placeholder​
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
placeholderType = ImageSource.PlaceholderType.NONE
)
Minimum Shimmer Time​
Control how long the shimmer is shown (even if the image loads fast):
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
minShimmerTime = 1500L // milliseconds, default 1000
)
Custom Placeholder​
Override with any composable:
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
placeholder = {
Box(
Modifier.fillMaxSize().background(Color.LightGray),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
)
Custom Error State​
AsyncPic(
source = ImageSource.Url("..."),
modifier = Modifier.size(200.dp),
error = {
Box(
Modifier.fillMaxSize().background(Color(0xFFFEE2E2)),
contentAlignment = Alignment.Center
) {
Text("Failed to load", color = Color.Red)
}
}
)