我最近从 Accompanist's 迁移ImagePainter
到 Coil's,以下是我更新后的相关代码。
val painter = rememberImagePainter(DRAWABLE_RESOURCE_ID)
when (painter.state) {
is ImagePainter.State.Empty -> Timber.w("Empty")
is ImagePainter.State.Loading -> {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.wrapContentSize()
) {
CircularProgressIndicator()
}
}
is ImagePainter.State.Success -> {
Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Fit,
modifier = Modifier
.padding(8.dp)
.size(84.dp)
.clip(RoundedCornerShape(corner = CornerSize(16.dp)))
)
}
is ImagePainter.State.Error -> Timber.e("Error")
}
现在这些图像不会渲染并且painter.state
总是Empty。我的旧版 Accompanist 实现在代码中此时显示了图像。如果我使用painterResource(resId)
Compose 的库存,它也可以工作。
painter
通过其状态执行 Coil 的 new 我缺少什么?