79278270

Date: 2024-12-13 12:14:48
Score: 0.5
Natty:
Report link

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)
)

enter image description here

See coil documentation for more.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: hasan.z