Communitygithub.com

Motion (Framer Motion) — 技能

在 React 中使用 motion/react 實現流暢、無障礙的動畫效果。適用於使用 motion、AnimatePresence、useScroll 及相關 API 添加動畫、手勢或佈局過渡時。需要 'use client' 邊界;不適用於純服務端渲染組件或無需動畫的情況。

Motion (Framer Motion) — 技能 是什麼?

這個 Motion (Framer Motion) 技能為 AI 開發助手提供了一套標準化的指導方針,幫助開發者在 React 專案中高效且無障礙地加入動畫。它適用於所有使用 motion/react 的場景,包括進入/離開動畫、佈局過渡、手勢交互(如 whileHover)以及滾動動畫。技能文件明確指出需要維護 'use client' 邊界,將客戶端 JavaScript 隔離在最小範圍內,並建議從簡單的透明度與位移動畫開始,再逐步引入彈簧物理效果。它還強調使用 AnimatePresence 處理條件渲染的進入/離開動畫、使用 layout 屬性實現平滑佈局變化,並透過 useReducedMotion 鉤子尊重使用者的減少動畫偏好。為了控制打包體積,對於較大的動畫場景建議採用 LazyMotion 按需載入。此外,該技能提供了實作與審查檢查清單,以及切入、佈局動畫和減少動畫的三個最小範例,並指出了常見錯誤,例如未用 AnimatePresence 包裹條件卸載的 UI、佈局動畫缺少 layout 屬性、將 motion 放在過大的客戶端樹中,以及在大型列表中動畫時缺乏虛擬化。適用平台包括 Claude Code、Cursor、Codex 等支援 SKILL.md 的 AI 編碼助手。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Asymmetric-al/core/tree/HEAD/.agents/skills/motion

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Motion (Framer Motion) — 技能 是做什麼的?

名稱: motion 目的: 使用 motion/react 在 React 中實現流暢、無障礙的動畫。 每當需要添加動畫、手勢或佈局過渡時使用此技能。

適用時機: 使用 motion/react(motion、AnimatePresence、useScroll 等)。 不應使用時機: 不需要動畫或組件為純服務端渲染時。

規則

  • 僅限客戶端邊界: Motion 需要 'use client';保持客戶端島嶼小巧。
  • 從簡開始: 在加入彈簧物理效果之前,先從透明度/位移開始。
  • 使用正確的工具: AnimatePresence 用於進/出動畫,layout 用於佈局動畫,whileHover/whileTap 用於手勢動畫。
  • 尊重減少動畫偏好: 使用 useReducedMotion()。
  • 打包體積紀律: 對於較大的動畫場景,使用 LazyMotion。

工作流程

  1. 確定 UX 目的(反饋、過渡、焦點)。
  2. 添加最小的 'use client' 邊界。
  3. 正確實現進/出或佈局過渡。
  4. 尊重減少動畫偏好。
  5. 檢查效能與打包體積。

檢查清單

實現檢查清單

  • 僅在需要的地方使用 'use client'
  • 定義減少動畫行為
  • AnimatePresence 包裹條件式 UI
  • 佈局過渡使用 layout

審查檢查清單

  • 動畫不會在每次渲染時重新執行
  • Motion 程式碼不會不必要地擴大客戶端樹

最小範例

進/出動畫

"use client";

import { AnimatePresence, motion } from "motion/react";

export function Toast({
  open,
  children,
}: {
  open: boolean;
  children: React.ReactNode;
}) {
  return (
    <AnimatePresence>
      {open ? (
        <motion.div
          initial={{ opacity: 0, y: 8 }}
          animate={{ opacity: 1, y: 0 }}
          exit={{ opacity: 0, y: 8 }}
          transition={{ duration: 0.18 }}
        >
          {children}
        </motion.div>
      ) : null}
    </AnimatePresence>
  );
}

佈局動畫

"use client";

import { motion } from "motion/react";

export function Expander({ open }: { open: boolean }) {
  return (
    <motion.div layout className="overflow-hidden rounded-md border p-3">
      <div className="font-medium">Title</div>
      {open ? <div className="mt-2 text-sm">More content...</div> : null}
    </motion.div>
  );
}

減少動畫

"use client";

import { motion, useReducedMotion } from "motion/react";

export function FadeIn({ children }: { children: React.ReactNode }) {
  const reduce = useReducedMotion();
  return (
    <motion.div
      initial={reduce ? false : { opacity: 0, y: 6 }}
      animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}
      transition={{ duration: 0.2 }}
    >
      {children}
    </motion.div>
  );
}

常見錯誤 / 陷阱

  • 在沒有 AnimatePresence 的情況下卸載元件(離開動畫永遠不會執行)
  • 在沒有 layout 屬性的情況下動畫佈局
  • 將 Motion 放在巨大的客戶端樹中
  • 在沒有虛擬化的情況下對大型列表進行動畫處理

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

Asymmetric-al/core

Build animations for Expo and React Native only, using Reanimated, Gesture Handler, Expo Router, and expo-haptics. Use when the target runtime is an Expo or React Native app. Do not use it for Core Next.js web motion; use `animate` for web. Only runs when explicitly invoked; it does not trigger on its own.

Asymmetric-al/core

Build an animation from scratch, making the decisions in the order that determines whether it feels right — should it animate at all, what purpose, which tool, which properties, which curve and duration, how it interrupts, how it exits. Writes the implementation. Use when asked to animate something, add motion, make a component feel alive, or build a transition. For critiquing existing motion use review-animations; for auditing a whole codebase use improve-animations. Only runs when explicitly invoked; it does not trigger on its own.

Asymmetric-al/core

Reverse-lookup glossary that turns a vague description of a web animation or motion effect into its exact term ("the bouncy thing when a popover opens" → Pop in; "the iOS rubber-band scroll" → Rubber-banding). Use when the user asks "what's it called when…", or describes a motion effect without knowing its name and wants the right word to prompt an AI or designer with. For naming an effect, not designing or building one.

Asymmetric-al/core

Inspect a Core UI or code surface for a small number of justified motion opportunities and explicitly identify what should remain static. Use when asked what should animate, where motion would improve feedback or comprehension, how to make an interface feel more alive without over-animating it, or whether a proposed animation is worth adding. Read-only; do not use to review or fix existing motion code or to implement animations.

Asymmetric-al/core

Survey a codebase's animation and motion code as a senior motion advisor, then produce a prioritized audit and self-contained implementation plans for other agents (or cheaper models) to execute. Read-only on source code — it plans improvements, it does not apply them. Use when the user asks to "improve the animations", "audit the motion", "make this app feel better", or wants a roadmap of animation fixes rather than a review of a single diff.

Asymmetric-al/core

Best practices for Remotion - Video creation in React

Asymmetric-al/core

Reviews animation and motion code against a high craft bar derived from Emil Kowalski's design engineering philosophy. Default to flagging; approval is earned.

相關技能