I'm using Coil 1.3.2 in Jetpack Compose and I have an Image like this
Image(
painter = rememberImagePainter(
data = imageUrl,
onExecute = { _, _ -> true },
builder = {
placeholder(R.drawable.icon)
}
),
contentScale = ContentScale.FillWidth,
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
)
How can I set a custom color and size for my placeholder icon ?
I didn't find any examples on the documentation
You can use
painter.stateto see if the image is still loading, and useBoxto display the desired placeholder. Note that theImageto be loaded must be in the view hierarchy, just definingrememberImagePainterwon't start loading.You can use either
ImageorIconfor the placeholder: if you need to change tint color, the second option seems cleaner:I'm using
contentAlignment = Alignment.Centerto center static size placeholder inside theBox, also you can addModifier.matchParentSize()to the placeholder so it'll be the same size as the image, usefillMaxSize(part)to takepartof parent space, etc.Also you can use AnimatedVisibility instead of
ifto add an animation.