Agent Skillsmaxrave-dev/SimpMusic › coil-compose

coil-compose

GitHub

提供Jetpack Compose中使用Coil库加载图片的专业指导。涵盖AsyncImage、rememberAsyncImagePainter及SubcomposeAsyncImage的使用场景,强调性能优化、缓存管理及最佳实践,适用于URL加载、状态处理及性能调优问题。

.claude/skills/coil-compose/SKILL.md maxrave-dev/SimpMusic

Trigger Scenarios

在Jetpack Compose中加载网络或本地图片 询问Coil库的AsyncImage组件用法 需要优化Compose中的图片加载性能 处理图片加载中的占位符或错误状态

Install

npx skills add maxrave-dev/SimpMusic --skill coil-compose -g -y
More Options

Non-standard path

npx skills add https://github.com/maxrave-dev/SimpMusic/tree/dev/.claude/skills/coil-compose -g -y

Use without installing

npx skills use maxrave-dev/SimpMusic@coil-compose

指定 Agent (Claude Code)

npx skills add maxrave-dev/SimpMusic --skill coil-compose -a claude-code -g -y

安装 repo 全部 skill

npx skills add maxrave-dev/SimpMusic --all -g -y

预览 repo 内 skill

npx skills add maxrave-dev/SimpMusic --list

SKILL.md

Frontmatter
{
    "name": "coil-compose",
    "description": "Expert guidance on using Coil for image loading in Jetpack Compose. Use this when asked about loading images from URLs, handling image states, or optimizing image performance in Compose."
}

Coil for Jetpack Compose

Instructions

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.

1. Primary Composable: AsyncImage

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

2. Low-Level Control: rememberAsyncImagePainter

Use 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] rememberAsyncImagePainter does not detect the size your image is loaded at on screen and always loads the image with its original dimensions by default. Use AsyncImage unless a Painter is 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()
)

3. Slot API: SubcomposeAsyncImage

Use SubcomposeAsyncImage when you need a custom slot API for different states (Loading, Success, Error).

[!CAUTION] Subcomposition is slower than regular composition. Avoid using SubcomposeAsyncImage in performance-critical areas like LazyColumn or LazyRow.

SubcomposeAsyncImage(
    model = "https://example.com/image.jpg",
    contentDescription = null,
    loading = {
        CircularProgressIndicator()
    },
    error = {
        Icon(Icons.Default.Error, contentDescription = null)
    }
)

4. Performance & Best Practices

  • Singleton ImageLoader: Use a single ImageLoader instance for the entire app to share the disk/memory cache.
  • Main-Safe: Coil executes image requests on a background thread automatically.
  • Crossfade: Always enable crossfade(true) in ImageRequest for a smoother transition from placeholder to success.
  • Sizing: Ensure contentScale is set appropriately to avoid loading larger images than necessary.

5. Checklist for implementation

  • Prefer AsyncImage over other variants.
  • Always provide a meaningful contentDescription or set it to null for decorative images.
  • Use crossfade(true) for better UX.
  • Avoid SubcomposeAsyncImage in lists.
  • Configure ImageRequest for specific needs like transformations (e.g., CircleCropTransformation).

Version History

  • 11f5926 Current 2026-07-30 20:16

Same Skill Collection

.claude/skills/android-accessibility/SKILL.md
.claude/skills/android-architecture/SKILL.md
.claude/skills/android-coroutines/SKILL.md
.claude/skills/android-data-layer/SKILL.md
.claude/skills/android-emulator-skill/SKILL.md
.claude/skills/android-gradle-logic/SKILL.md
.claude/skills/android-retrofit/SKILL.md
.claude/skills/android-testing/SKILL.md
.claude/skills/android-viewmodel/SKILL.md
.claude/skills/compose-navigation/SKILL.md
.claude/skills/compose-performance-audit/SKILL.md
.claude/skills/compose-ui/SKILL.md
.claude/skills/gradle-build-performance/SKILL.md
.claude/skills/jetpack-compose/SKILL.md
.claude/skills/kotlin-concurrency-expert/SKILL.md
.claude/skills/marketing-ideas/SKILL.md
.claude/skills/mobile-android-design/SKILL.md
.claude/skills/xml-to-compose-migration/SKILL.md
.claude/skills/find-skills/SKILL.md
.claude/skills/kmp/SKILL.md
.claude/skills/ui-ux-pro-max/SKILL.md

Metadata

Files
0
Version
f7205d5
Hash
624e889f
Indexed
2026-07-30 20:16

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-31 16:39
浙ICP备14020137号-1 $방문자$