mcpField
R
react-spring

react-spring

github.com/dylantarreデザイン・UI132521 回インストール43 週間前に更新
リポジトリ

react-spring について

React 開発者向けのアニメーション設計スキルです。React Spring の物理ベースの動きでディズニーの 12 原則を適用し、主要なフックや設定方法も紹介します。

主な機能

  1. 01物理ベースで 12 原則を適用
  2. 02単体・複数要素のアニメーション
  3. 03段階的・連続・遷移アニメーション
  4. 04バネのパラメーターとプリセット

活用シーン

  1. 01UI 要素にバネアニメーションを追加
  2. 02連続または段階的な動きを構成
  3. 03要素のマウント・アンマウントを演出

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dylantarre/animation-principles --skill react-spring

インストール後、Claude Code で/react-springを入力して読み込まれたか確認します。

詳細

React Spring アニメーションの原則

React Spring のスプリング物理システムを使って、ディズニーのアニメーション原則をすべて実装します。

1. スクワッシュとストレッチ

const [springs, api] = useSpring(() => ({
  scaleX: 1,
  scaleY: 1,
  config: { tension: 300, friction: 10 }
}));

api.start({ scaleX: 1.2, scaleY: 0.8 });
<animated.div style={springs} />

2. 予備動作

const [props, api] = useSpring(() => ({ y: 0, scaleY: 1 }));

const jump = async () => {
  await api.start({ y: 10, scaleY: 0.9 }); // wind up
  api.start({ y: -200, config: { tension: 200 } }); // action
};

3. 演出

const bgSpring = useSpring({ filter: 'blur(3px)', opacity: 0.6 });
const heroSpring = useSpring({ scale: 1.1, zIndex: 10 });

4. ストレート・アヘッドとポーズ・トゥ・ポーズ

const [props] = useSpring(() => ({
  from: { x: 0, y: 0 },
  to: [
    { x: 100, y: -50 },
    { x: 200, y: 0 },
    { x: 300, y: -30 }
  ]
}));

5. フォロースルーとオーバーラッピング・アクション

const bodySpring = useSpring({ x: 200 });
const hairSpring = useSpring({ x: 200, delay: 50 });
const capeSpring = useSpring({ x: 200, delay: 100, config: { friction: 15 } });

6. スローインとスローアウト

const spring = useSpring({
  x: 300,
  config: {
    tension: 170,
    friction: 26 // balanced = smooth in/out
  }
});
// High tension + low friction = fast
// Low tension + high friction = slow

7. アーク

const [props] = useSpring(() => ({
  to: async (next) => {
    await next({ x: 100, y: -100 });
    await next({ x: 200, y: 0 });
  },
  config: { tension: 200, friction: 20 }
}));

8. 副次動作

const buttonSpring = useSpring({ scale: hover ? 1.05 : 1 });
const iconSpring = useSpring({
  rotate: hover ? 15 : 0,
  delay: 50
});

9. タイミング

const configs = {
  fast: { tension: 400, friction: 30 },
  normal: { tension: 170, friction: 26 },
  slow: { tension: 100, friction: 40 },
  wobbly: { tension: 180, friction: 12 }
};
// Or use presets: config.gentle, config.stiff, config.slow

10. 誇張

const spring = useSpring({
  scale: 1.5,
  rotate: 720,
  config: { tension: 200, friction: 8 } // low friction = overshoot
});

11. 立体感のある描画

const spring = useSpring({
  transform: 'perspective(1000px) rotateX(45deg) rotateY(30deg)'
});

12. 魅力

const cardSpring = useSpring({
  scale: hover ? 1.02 : 1,
  boxShadow: hover
    ? '0 20px 40px rgba(0,0,0,0.2)'
    : '0 5px 15px rgba(0,0,0,0.1)',
  config: config.gentle
});

useTrail で段階的にアニメーション

const trail = useTrail(items.length, {
  opacity: show ? 1 : 0,
  y: show ? 0 : 20,
  config: { tension: 200, friction: 20 }
});

trail.map((props, i) => <animated.div style={props}>{items[i]}</animated.div>)

React Spring の主な機能

  • useSpring - 単一のアニメーション
  • useSprings - 複数のスプリング
  • useTrail - 段階的なアニメーション
  • useChain - アニメーションの連続再生
  • useTransition - マウント/アンマウント時のアニメーション
  • config プリセット - gentle、stiff、slow、molasses
  • 物理ベース:tension、friction、mass、velocity

コメント