Skip to main content

Basic Usage

Load from URL​

The simplest usage — pass a URL string wrapped in ImageSource.Url:

AsyncPic(
source = ImageSource.Url("https://example.com/photo.jpg"),
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
)

Load from Resources​

To load a local drawable resource:

AsyncPic(
source = ImageSource.Resources(R.drawable.my_image),
modifier = Modifier.size(120.dp)
)

Custom Shape​

Pass any Shape to clip the image:

// Rounded corners
AsyncPic(
source = ImageSource.Url("https://example.com/photo.jpg"),
modifier = Modifier.size(200.dp),
shape = RoundedCornerShape(16.dp)
)

// Circle
AsyncPic(
source = ImageSource.Url("https://example.com/avatar.jpg"),
modifier = Modifier.size(56.dp),
shape = CircleShape
)

ContentScale​

Control how the image fills its bounds:

AsyncPic(
source = ImageSource.Url("https://example.com/photo.jpg"),
modifier = Modifier.fillMaxWidth().height(200.dp),
contentScale = ContentScale.FillBounds // stretch to fill
// ContentScale.Fit // letterbox
// ContentScale.Crop // default, center-crop
)

Success & Error Callbacks​

AsyncPic(
source = ImageSource.Url("https://example.com/photo.jpg"),
modifier = Modifier.size(200.dp),
onSuccess = {
println("Image loaded successfully!")
},
onError = { throwable ->
println("Failed: ${throwable.message}")
}
)