ios-animation-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

iOS Animation Code Review

iOS 动画代码审查

Quick Reference

快速参考

Issue TypeReference
Spring parameters, withAnimation misuse, phase/keyframe bugsreferences/swiftui-animation-patterns.md
Frame drops, offscreen rendering, main thread blockingreferences/performance.md
Reduce Motion, VoiceOver, motion sensitivityreferences/accessibility.md
Transition protocol, matchedGeometryEffect, navigation transitionsreferences/transitions.md
问题类型参考文档
弹簧参数、withAnimation 误用、阶段/关键帧错误references/swiftui-animation-patterns.md
掉帧、离屏渲染、主线程阻塞references/performance.md
减少动态效果、VoiceOver、运动敏感度references/accessibility.md
Transition 协议、matchedGeometryEffect、导航转场references/transitions.md

Output Format

输出格式

Report each finding as:
[FILE:LINE] ISSUE_TITLE
Example:
[AnimatedCard.swift:42] Missing Reduce Motion fallback for spring animation
All details, code suggestions, and rationale follow after the header line.
每个问题报告格式如下:
[文件:行号] 问题标题
示例:
[AnimatedCard.swift:42] 弹簧动画缺少减少动态效果的降级方案
所有细节、代码建议及原理说明均在标题行之后列出。

Review Checklist

审查清单

  • @Environment(\.accessibilityReduceMotion)
    checked — animations have Reduce Motion fallback
  • Animation is not the sole feedback channel — important state changes pair with haptics (
    .sensoryFeedback
    ) or audio
  • Custom animation isn't duplicating system-provided motion (standard nav transitions, sheet presentation, SF Symbol effects)
  • Animations on frequent interactions are brief and unobtrusive — or absent (system handles it)
  • All animations are interruptible — user is never forced to wait for completion before interacting
  • Spring animations use
    duration
    /
    bounce
    parameters (not raw mass/stiffness/damping unless UIKit/CA)
  • No deprecated
    .animation()
    without
    value:
    parameter
  • withAnimation
    wraps state changes, not view declarations
  • matchedGeometryEffect
    IDs are stable and unique within the namespace
  • geometryGroup()
    used when parent geometry animates with child views appearing
  • Looping animations (
    PhaseAnimator
    ,
    symbolEffect
    ) have finite phases or appropriate trigger
  • No
    CATransaction.setAnimationDuration()
    in UIView-backed layers (use UIView.animate instead)
  • Interactive animations handle interruption (re-trigger mid-flight doesn't break state)
  • Shadow animations provide explicit
    shadowPath
    (avoids per-frame recalculation)
  • Gesture-driven animations preserve velocity on release for natural completion
  • Gesture-driven feedback follows spatial expectations (dismiss direction matches reveal direction)
  • No animation of
    .id()
    modifier (destroys view identity — use
    transition
    or
    matchedGeometryEffect
    instead)
  • 已检查
    @Environment(\.accessibilityReduceMotion)
    —— 动画具备减少动态效果的降级方案
  • 动画并非唯一反馈渠道 —— 重要状态变更搭配触觉反馈(
    .sensoryFeedback
    )或音频
  • 自定义动画未重复系统提供的动效(标准导航转场、弹窗展示、SF Symbol 效果)
  • 频繁交互场景下的动画简洁且不突兀 —— 或直接由系统处理
  • 所有动画均可中断 —— 用户无需等待动画完成即可进行交互
  • 弹簧动画使用
    duration
    /
    bounce
    参数(除非是 UIKit/CA 场景,否则不使用原始的 mass/stiffness/damping 参数)
  • 无未指定
    value:
    参数的废弃
    .animation()
    用法
  • withAnimation
    包裹状态变更逻辑,而非视图声明
  • matchedGeometryEffect
    的 ID 在命名空间内稳定且唯一
  • 父级几何动画伴随子视图出现时已使用
    geometryGroup()
  • 循环动画(
    PhaseAnimator
    symbolEffect
    )具备有限阶段或合适的触发条件
  • UIView 托管的图层中未使用
    CATransaction.setAnimationDuration()
    (改用 UIView.animate)
  • 交互式动画可处理中断(中途重新触发不会破坏状态)
  • 阴影动画提供了明确的
    shadowPath
    (避免逐帧重新计算)
  • 手势驱动的动画在释放时保留速度,以实现自然完成效果
  • 手势驱动的反馈符合空间预期(关闭方向与展示方向一致)
  • 未对
    .id()
    修饰器执行动画(会破坏视图标识 —— 改用
    transition
    matchedGeometryEffect

When to Load References

何时加载参考文档

  • Incorrect spring setup or
    withAnimation
    scope issues → swiftui-animation-patterns.md
  • Hitches, dropped frames, or expensive animations in scroll views → performance.md
  • Missing Reduce Motion handling or motion accessibility → accessibility.md
  • matchedGeometryEffect
    glitches or custom
    Transition
    bugs → transitions.md
  • 弹簧设置错误或
    withAnimation
    作用域问题 → swiftui-animation-patterns.md
  • 卡顿、掉帧或滚动视图中的高开销动画 → performance.md
  • 缺少减少动态效果处理或动效可访问性问题 → accessibility.md
  • matchedGeometryEffect
    异常或自定义
    Transition
    错误 → transitions.md

Review Questions

审查问题

  1. Does every animation have a Reduce Motion fallback that preserves the information conveyed? Is animation the only feedback channel, or are haptics/audio supplementing it?
  2. Is this custom animation necessary, or does the system already provide it (standard transitions, SF Symbol effects, Liquid Glass)?
  3. Could this animation cause frame drops — is it animating expensive properties (blur, shadow without path, mask) in a list or scroll view?
  4. Are all animations interruptible? Can the user act without waiting for completion? Does gesture-driven feedback follow spatial expectations?
  5. Is
    withAnimation
    scoped to the minimal state change needed, or is it wrapping unrelated mutations?
  6. For
    matchedGeometryEffect
    — are source and destination using the same ID and namespace, and is only one visible at a time?
  1. 每个动画是否都有保留信息传递的减少动态效果降级方案?动画是唯一反馈渠道,还是有触觉/音频作为补充?
  2. 这个自定义动画是否必要,还是系统已提供对应的动效(标准转场、SF Symbol 效果、Liquid Glass)?
  3. 该动画是否会导致掉帧 —— 是否在列表或滚动视图中对高开销属性(模糊、无路径的阴影、蒙版)执行动画?
  4. 所有动画是否均可中断?用户无需等待完成即可操作吗?手势驱动的反馈是否符合空间预期?
  5. withAnimation
    的作用域是否仅限于所需的最小状态变更,还是包裹了无关的修改操作?
  6. 对于
    matchedGeometryEffect
    —— 源端和目标端是否使用相同的 ID 和命名空间,且同一时间仅显示其中一方?