Agent Skills › chrisbanes/skills › compose-animations

compose-animations

GitHub

指导Jetpack Compose动画开发,涵盖API选择、生命周期管理及内容身份处理。用于编写或审查可见性切换、属性过渡及状态协调等动画逻辑。

skills/compose-animations/SKILL.md chrisbanes/skills

Trigger Scenarios

编写Compose动画代码 审查Compose动画实现

Install

npx skills add chrisbanes/skills --skill compose-animations -g -y
More Options

Use without installing

npx skills use chrisbanes/skills@compose-animations

指定 Agent (Claude Code)

npx skills add chrisbanes/skills --skill compose-animations -a claude-code -g -y

安装 repo 全部 skill

npx skills add chrisbanes/skills --all -g -y

预览 repo 内 skill

npx skills add chrisbanes/skills --list

SKILL.md

Frontmatter
{
    "name": "compose-animations",
    "description": "Use when writing or reviewing Jetpack Compose motion: visibility enter\/exit, animating one property toward a target, color or size transitions, multiple properties from one state, switching composable content, or choosing between AnimatedVisibility, animate*AsState, rememberTransition, AnimatedContent, and Crossfade."
}

Compose: animations

Core principle

Pick the smallest API that expresses the motion and its lifecycle.

Procedure

  1. Identify the job: show or hide a subtree, animate one value, coordinate values from one state, resize content, swap content, or handle user-driven motion.
  2. Choose the matching API from the table. Prefer target-state APIs; use Animatable only when gestures, interruption, or imperative control require it.
  3. Check lifecycle: an alpha animation keeps content composed; AnimatedVisibility removes it after exit. Do not use a fade when unmounting is required.
  4. For AnimatedContent, render from the content lambda target and choose a contentKey only when visual identity differs from payload equality. In a swap between distinct items, keep the target value as the identity (the default) or key by a stable item ID; do not collapse different items to a shared presence or branch key. In a review, name any rendered expression that captures outer target state and recommend using the lambda target there. If a test must prove transition identity, check outgoing and incoming content during the overlap; checking only the settled destination misses a shared-identity bug. Read AnimatedContent identity for state-holder details.
  5. Keep animated State in layout or draw block modifiers when it changes at frame rate; route deeper diagnosis to Compose performance.
  6. Use Navigation Compose transitions for destination swaps it owns, and dedicated libraries for art-based motion.
  7. Finish when the API, lifecycle, and content identity match the UI, no simpler API fits, and the relevant behavior is verified.

API choice

Need Prefer
Show/hide a subtree with enter/exit semantics AnimatedVisibility
One value follows state animate*AsState
Several values follow one boolean, enum, or sealed state rememberTransition plus child animations
Child size changes Modifier.animateContentSize()
Different composable trees fill one region AnimatedContent, or Crossfade for the simple case
Drag, fling, interruption, or imperative control Animatable

Use an AnimationSpec when the default motion is wrong and a distinct label when multiple animations need tooling visibility.

val width by animateDpAsState(
    targetValue = if (expanded) 200.dp else 56.dp,
    animationSpec = spring(dampingRatio = 0.7f),
    label = "fabWidth",
)

For values that must remain synchronized, define them on one transition rather than several independent animate*AsState calls:

val transition = rememberTransition(targetState = phase, label = "phase")
val alpha by transition.animateFloat(label = "alpha") { target ->
    if (target == Phase.Visible) 1f else 0f
}
val offset by transition.animateDp(label = "offset") { target ->
    if (target == Phase.Visible) 0.dp else 24.dp
}

For animated fills, prefer drawBehind { drawRect(color.value) } over a value-form background when the color updates every frame. For an API ambiguity, start with the official Choose an animation API guide; use rememberInfiniteTransition for repeating cycles and SeekableTransitionState for seekable or test-controlled progress.

When not to use this skill

Version History

  • 2026.9.25 Current 2026-09-27 20:22

    优化了AnimatedContent的内容键选择策略,增加了关于渲染表达式捕获外部目标状态的审查建议,并补充了测试中验证转换身份的说明。

  • 2026.8.24 2026-08-27 17:15

    精简了技能指令的冗余描述,优化了核心原则和审查流程的表达清晰度。

  • 2026.8.16 2026-08-19 19:31

    更新审查步骤第4点:明确 AnimatedContent.contentKey 应基于视觉形状而非数据变化选择;增加关于 animateFloatAsState 仅改变透明度且保留组件树的说明。

  • 2026.8.5 2026-08-16 02:44

    将多个细粒度的 Kotlin 和 Compose 技能整合为五个自包含集群,更新全局路由和迁移文档。

  • 2026.7.21 2026-07-24 12:24

Same Skill Collection

skills/android-benchmark-comparison/SKILL.md
skills/compose-component-design/SKILL.md
skills/compose-focus-navigation/SKILL.md
skills/compose-modifier-and-layout-style/SKILL.md
skills/compose-performance/SKILL.md
skills/compose-recomposition-performance/SKILL.md
skills/compose-side-effects/SKILL.md
skills/compose-slot-api-pattern/SKILL.md
skills/compose-stability-diagnostics/SKILL.md
skills/compose-state-and-effects/SKILL.md
skills/compose-state-authoring/SKILL.md
skills/compose-state-deferred-reads/SKILL.md
skills/compose-state-hoisting/SKILL.md
skills/compose-state-holder-ui-split/SKILL.md
skills/compose-ui-testing-patterns/SKILL.md
skills/gradle-run/SKILL.md
skills/grounded-writing/SKILL.md
skills/implement-issue/SKILL.md
skills/kotlin-api-design/SKILL.md
skills/kotlin-concurrency-and-flow/SKILL.md
skills/kotlin-control-flow/SKILL.md
skills/kotlin-coroutines-structured-concurrency/SKILL.md
skills/kotlin-flow-state-event-modeling/SKILL.md
skills/kotlin-functions/SKILL.md
skills/kotlin-multiplatform-expect-actual/SKILL.md
skills/kotlin-types-value-class/SKILL.md
skills/release-kotlin-library/SKILL.md
skills/run-github-project/SKILL.md
skills/shepherd/SKILL.md
skills/to-plan/SKILL.md
skills/using-chrisbanes-skills/SKILL.md
skills/implement-with-subagents/SKILL.md

Metadata

Files
0
Version
2026.9.25
Hash
eb94fc22
Indexed
2026-07-24 12:24

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-29 23:39
浙ICP备14020137号-1