Код: Выделить всё
fun coilPainter(
imageUrl: Any?,
scale: Scale = Scale.FIT,
size: Size = Size.ORIGINAL,
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.decoderFactory(SvgDecoder.Factory ())
.crossfade(true)
.size(size)
.scale(scale)
.diskCachePolicy(CachePolicy.ENABLED)
.build(),
)
Код: Выделить всё
fun ImageProfileLoader(
image: Any? = null,
text: String? = null,
isDefaultBankIcon:Boolean = false,
backgroundColor: Color = Color.Gray,
size: Dp = 55.dp,
fontSize: Dp = 16.dp,
Код: Выделить всё
val painter = coilPainter(imageUrl = image).state
Box(
modifier = Modifier
.size(size)
.background(backgroundColor, shape = CircleShape)
.clip(CircleShape),
contentAlignment = Alignment.Center
){
if(painter is AsyncImagePainter.State.Error){
if (text?.isEmpty() == true){
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(R.drawable.default_image_profile).takeIf { !isDefaultBankIcon }?:painterResource(R.drawable.default_bank_icon),
contentDescription = "",
contentScale = ContentScale.Crop
)
} else {
TextCustom(
text = text?.first()?.uppercaseChar().toString(),
fontSize = fontSize,
color = Color171717
)
}
}
if(painter is AsyncImagePainter.State.Success){
Image(
modifier = Modifier.fillMaxSize(),
painter = painter.painter,
contentDescription = "",
contentScale = ContentScale.Crop
)
}
if(painter is AsyncImagePainter.State.Loading){
Spacer(
modifier = Modifier
.size(size)
.clip(CircleShape)
.shimmerEffect()
)
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... hile-other