Loading an image with Coil is straightforward. Use SubcomposeAsyncImage from Coil, which handles everything for you. It provides callbacks like loading, success, and error for better control.
@Composable
fun LoadImage(
model: String,
modifier: Modifier = Modifier
) {
SubcomposeAsyncImage(
modifier = modifier,
model = model,
loading = {
Box(modifier = Modifier.shimmerLoading())
},
contentDescription = null,
)
}
To use this function, simply call it and specify your desired size.
LoadImage(
model = uiState.image,
modifier = Modifier.size(400.dp, 200.dp)
)
See coil documentation for more.