coil-compose by new-silvermoon/awesome-android-agent-skills
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill coil-compose在 Jetpack Compose 中实现图片加载时,请使用 Coil(Coroutines Image Loader)。由于其高效性和无缝集成,它是 Compose 的推荐库。
AsyncImage对于大多数用例,请使用 AsyncImage。它会自动处理尺寸解析,并支持标准的 Image 参数。
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data("https://example.com/image.jpg")
.crossfade(true)
.build(),
placeholder = painterResource(R.drawable.placeholder),
error = painterResource(R.drawable.error),
contentDescription = stringResource(R.string.description),
contentScale = ContentScale.Crop,
modifier = Modifier.clip(CircleShape)
)
rememberAsyncImagePainter仅当你需要一个 而不是可组合项时(例如,用于 或 ),或者当你需要手动观察加载状态时,才使用 。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
PainterCanvasIconrememberAsyncImagePainter[!WARNING]
rememberAsyncImagePainter不会检测图片在屏幕上加载的尺寸,并且默认始终以原始尺寸加载图片。除非严格需要Painter,否则请使用AsyncImage。
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.data("https://example.com/image.jpg")
.size(Size.ORIGINAL) // 如果需要,显式定义尺寸
.build()
)
SubcomposeAsyncImage当你需要为不同状态(加载中、成功、错误)提供自定义插槽 API 时,请使用 SubcomposeAsyncImage。
[!CAUTION] 子组合比常规组合慢。避免在性能关键区域(如
LazyColumn或LazyRow)中使用SubcomposeAsyncImage。
SubcomposeAsyncImage(
model = "https://example.com/image.jpg",
contentDescription = null,
loading = {
CircularProgressIndicator()
},
error = {
Icon(Icons.Default.Error, contentDescription = null)
}
)
ImageLoader 实例,以共享磁盘/内存缓存。ImageRequest 中启用 crossfade(true),以实现从占位符到成功加载的更平滑过渡。contentScale,以避免加载比所需尺寸更大的图片。AsyncImage 而非其他变体。contentDescription,或者对于装饰性图片将其设置为 null。crossfade(true) 以获得更好的用户体验。SubcomposeAsyncImage。CircleCropTransformation)配置 ImageRequest。每周安装量
109
代码仓库
GitHub 星标数
552
首次出现
2026 年 1 月 29 日
安全审计
已安装于
opencode101
codex100
claude-code81
gemini-cli76
github-copilot75
kimi-cli73
When implementing image loading in Jetpack Compose, use Coil (Coroutines Image Loader). It is the recommended library for Compose due to its efficiency and seamless integration.
AsyncImageUse AsyncImage for most use cases. It handles size resolution automatically and supports standard Image parameters.
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data("https://example.com/image.jpg")
.crossfade(true)
.build(),
placeholder = painterResource(R.drawable.placeholder),
error = painterResource(R.drawable.error),
contentDescription = stringResource(R.string.description),
contentScale = ContentScale.Crop,
modifier = Modifier.clip(CircleShape)
)
rememberAsyncImagePainterUse rememberAsyncImagePainter only when you need a Painter instead of a composable (e.g., for Canvas or Icon) or when you need to observe the loading state manually.
[!WARNING]
rememberAsyncImagePainterdoes not detect the size your image is loaded at on screen and always loads the image with its original dimensions by default. UseAsyncImageunless aPainteris strictly required.
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.data("https://example.com/image.jpg")
.size(Size.ORIGINAL) // Explicitly define size if needed
.build()
)
SubcomposeAsyncImageUse SubcomposeAsyncImage when you need a custom slot API for different states (Loading, Success, Error).
[!CAUTION] Subcomposition is slower than regular composition. Avoid using
SubcomposeAsyncImagein performance-critical areas likeLazyColumnorLazyRow.
SubcomposeAsyncImage(
model = "https://example.com/image.jpg",
contentDescription = null,
loading = {
CircularProgressIndicator()
},
error = {
Icon(Icons.Default.Error, contentDescription = null)
}
)
ImageLoader instance for the entire app to share the disk/memory cache.crossfade(true) in ImageRequest for a smoother transition from placeholder to success.contentScale is set appropriately to avoid loading larger images than necessary.AsyncImage over other variants.contentDescription or set it to null for decorative images.crossfade(true) for better UX.SubcomposeAsyncImage in lists.ImageRequest for specific needs like transformations (e.g., CircleCropTransformation).Weekly Installs
109
Repository
GitHub Stars
552
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode101
codex100
claude-code81
gemini-cli76
github-copilot75
kimi-cli73
ESLint迁移到Oxlint完整指南:JavaScript/TypeScript项目性能优化工具
1,600 周安装