Communitygithub.com

React Native Reanimated

React Native Reanimated は、UIスレッド上でアニメーションを実行することで、JavaScriptスレッドがビジーな状態でも60fpsのスムーズなアニメーションを実現するライブラリです。このスキルは、ワークレットや共有値、CSSトランジション、ジェスチャー、スクロール駆動アニメーションなど、Reanimated 4の主要機能をカバーします。

React Native Reanimated とは?

このスキルは、React Nativeアプリケーションにおいて、高性能でスムーズなアニメーションを実現するためのアニメーションライブラリ「Reanimated」に特化しています。Reanimated 4 (バージョン4.7.0) を対象としており、UIスレッド上でアニメーションを実行するワークレット(worklets)や共有値(shared values)を用いることで、JavaScriptスレッドの負荷に関わらず、60fpsの安定したパフォーマンスを提供します。このスキルが有用なシナリオとしては、単純なフェードやスライドを超えた、ジェスチャー駆動のインタラクション(スワイプして削除、ドラッグ&リオーダー、ピンチズーム)、スクロールに連動したパララックス効果、リストアイテムのレイアウトアニメーション、画面遷移時の共有要素トランジションなどが挙げられます。スキルの内容は、Reanimated 4のセットアップ手順、共有値とアニメーションスタイルの基本的な使い方、Gesture Handlerと連携したジェスチャーアニメーション、宣言的なレイアウトアニメーション、スクロール駆動アニメーション、さらにReanimated 4で新たに追加されたCSSトランジションと共有要素トランジションの実験的機能を網羅しています。各機能の実装例として、Tinder風のカードスワイプUIや、スナップポイントに吸着するボトムシートのコードが含まれており、開発者はこれらのサンプルを基に実践的なアニメーションを素早く実装できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/TerminalSkills/skills/tree/HEAD/skills/react-native-reanimated

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

React Native Reanimated は何をしますか?

概要

Reanimated は、ネイティブUIスレッド上でアニメーションを実行するため、JavaScriptスレッドがビジーな状態でも、60fps(またはディスプレイのリフレッシュレート)を維持します。ワークレット(worklets)と呼ばれる、JSIを介してUIスレッドで実行される小さなJavaScript関数を使用します。ジェスチャー駆動のインタラクション、レイアウトトランジション、スクロールベースのエフェクト、共有要素トランジションなど、React Nativeにおける高品質なアニメーションの標準的なライブラリです。

このスキルは Reanimated 4(4.7.0、2026年9月リリース)を対象としています。バージョン4は新しいアーキテクチャでのみ動作し、ワークレットを別の react-native-worklets パッケージに分離し、CSSスタイルのトランジションとアニメーションを追加します。古いアーキテクチャを使用しているアプリは3.xに留まる必要があり、3.xは積極的にはメンテナンスされていません。

使用するタイミング

  • React Nativeでの単純なopacity/transformを超えたアニメーション全般
  • ジェスチャー駆動のインタラクション(スワイプして削除、ドラッグして並べ替え、ピンチでズーム)
  • スクロール駆動アニメーション(パララックスヘッダー、スティッキー要素)
  • レイアウトアニメーション(リストに項目が出入りする際のアニメーション)
  • 画面間の共有要素トランジション(4.xでは実験的機能)

手順

セットアップ

# Expo: SDKによって固定されたバージョンをインストール(SDK 57: Reanimated 4.5, Worklets 0.10, Gesture Handler 2.32)
npx expo install react-native-reanimated react-native-worklets react-native-gesture-handler
npx expo prebuild        # 開発ビルドの場合のみ: ios/ および android/ ディレクトリを再生成

# React Native Community CLI
npm install react-native-reanimated react-native-worklets react-native-gesture-handler
cd ios && pod install && cd ..
npm start -- --reset-cache
  • Expo: babel-preset-expo がWorklets Babelプラグインを自動で追加するため、babel.config.js にリストアップする必要はありません。
  • Community CLI: babel.config.js の plugins の 最後 のエントリとして 'react-native-worklets/plugin' を追加します。Reanimated 3時代の名前 react-native-reanimated/plugin も4.xでは解決されますが、これはレガシーな表記です。
  • 各Reanimatedマイナーバージョンは、特定の react-native-worklets および React Native のバージョンと互換性があります(4.7には Worklets 0.13 と RN 0.86~0.88 が必要)。手動アップグレードの前に互換性テーブルを確認してください。
  • ジェスチャーを使用する場合は、アプリのルートを react-native-gesture-handler の GestureHandlerRootView でラップし、style={{ flex: 1 }} を設定します。

共有値とアニメーションスタイル

// components/FadeIn.tsx — 共有値を使用した基本的なアニメーション
import Animated, { useSharedValue, useAnimatedStyle, withTiming, withSpring } from "react-native-reanimated";
import { type ReactNode, useEffect } from "react";

export function FadeInCard({ children }: { children: ReactNode }) {
  const opacity = useSharedValue(0);
  const translateY = useSharedValue(20);
  useEffect(() => {
    opacity.value = withTiming(1, { duration: 600 });
    translateY.value = withSpring(0);
  }, []);
  const animatedStyle = useAnimatedStyle(() => ({
    opacity: opacity.value,
    transform: [{ translateY: translateY.value }],
  }));

  return <Animated.View style={[{ backgroundColor: "white", padding: 16 }, animatedStyle]}>{children}</Animated.View>;
}

.value の読み書きは、エフェクト、イベントハンドラ、ワークレット内でのみ行ってください。レンダリング中に行わないでください。React Compilerを使用する場合は、.value の代わりに opacity.get() と opacity.set(1) を使用します。

ジェスチャーアニメーション

// components/SwipeToDelete.tsx — スワイプジェスチャーを使用したアニメーション
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from "react-native-reanimated";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { scheduleOnRN } from "react-native-worklets";
import type { ReactNode } from "react";

export function SwipeToDelete({ onDelete, children }: { onDelete: () => void; children: ReactNode }) {
  const translateX = useSharedValue(0);
  const pan = Gesture.Pan()
    .onUpdate((event) => {
      translateX.value = Math.min(0, event.translationX);   // 左スワイプのみ許可
    })
    .onEnd((event) => {
      if (event.translationX < -150) {
        translateX.value = withSpring(-400);
        scheduleOnRN(onDelete);            // UIスレッドからJSスレッドの関数を呼び出す
      } else {
        translateX.value = withSpring(0);  // 元の位置にスナップバック
      }
    });
  const animatedStyle = useAnimatedStyle(() => ({ transform: [{ translateX: translateX.value }] }));
  return (
    <GestureDetector gesture={pan}>
      <Animated.View style={animatedStyle}>{children}</Animated.View>
    </GestureDetector>
  );
}

scheduleOnRN(fn, ...args) は、4.xで非推奨となった runOnJS(fn)(...args) の代わりに使用します。Gesture.Pan() は Gesture Handler 2 のビルダーAPIで、Expo SDK 57がインストールするものです。Gesture Handler 3 ではこれが維持され、フック(usePanGesture({ onUpdate, onDeactivate }))が追加されています。onStart/onEnd はそれぞれ onActivate/onDeactivate と名前が変わっています。

レイアウトアニメーション

// components/AnimatedList.tsx — アイテムが自動的にアニメーションしながら出入りする
import Animated, { FadeInDown, FadeOutLeft, LinearTransition } from "react-native-reanimated";
import { Pressable, Text } from "react-native";

type Item = { id: string; title: string };
export function AnimatedList({ items, onRemove }: { items: Item[]; onRemove: (id: string) => void }) {
  return (
    <Animated.FlatList
      data={items}
      keyExtractor={(item) => item.id}
      itemLayoutAnimation={LinearTransition}   // 残った行がスライドして詰められる(単一カラムのみ)
      renderItem={({ item, index }) => (
        <Animated.View
          entering={FadeInDown.delay(index * 100).springify()}
          exiting={FadeOutLeft.duration(300)}
          style={{ backgroundColor: "white", padding: 16, marginVertical: 4, borderRadius: 8 }}
        >
          <Text>{item.title}</Text>
          <Pressable onPress={() => onRemove(item.id)}><Text style={{ color: "#dc2626" }}>Remove</Text></Pressable>
        </Animated.View>
      )}
    />
  );
}

スクロール駆動アニメーション

// components/ParallaxHeader.tsx — スクロールに応じたパララックス効果
import Animated, {
  useAnimatedScrollHandler, useSharedValue, useAnimatedStyle, interpolate, Extrapolation,
} from "react-native-reanimated";
import { Text } from "react-native";

export function ParallaxHeader() {
  const scrollY = useSharedValue(0);
  const scrollHandler = useAnimatedScrollHandler({
    onScroll: (event) => { scrollY.value = event.contentOffset.y; },
  });
  const headerStyle = useAnimatedStyle(() => ({
    height: interpolate(scrollY.value, [-100, 0, 200], [400, 300, 100], Extrapolation.CLAMP),
    opacity: interpolate(scrollY.value, [0, 200], [1, 0.3], Extrapolation.CLAMP),
  }));

  return (
    <>
      <Animated.View style={[{ backgroundColor: "#2563eb" }, headerStyle]}>
        <Text style={{ color: "white", fontSize: 28, fontWeight: "bold" }}>トレイルログ</Text>
      </Animated.View>
      <Animated.ScrollView onScroll={scrollHandler}>{/* コンテンツ */}</Animated.ScrollView>
    </>
  );
}

オフセットのみが必要な場合は、useScrollOffset(animatedRef)(3.xでは useScrollViewOffset という名前)を使用すると、ハンドラなしで共有値としてオフセットを取得できます。

CSSトランジションと共有要素(Reanimated 4)

// 状態変化が自動的にアニメーションする:共有値もフックも不要
<Animated.View
  style={{
    height: 80,
    width: expanded ? 240 : 120,
    backgroundColor: expanded ? "#16a34a" : "#2563eb",
    transitionProperty: ["width", "backgroundColor"],
    transitionDuration: 300,
  }}
/>

// ネイティブスタックの2つの画面で同じタグを使用すると、要素が画面間でアニメーションする
<Animated.Image sharedTransitionTag="trail-42-photo" source={{ uri: photoUrl }} style={{ width: 120, height: 120 }} />

共有要素トランジションは4.xでは実験的機能であり、デフォルトでは無効になっています。有効にするには、アプリの package.json(4.2以降)に "reanimated": { "staticFeatureFlags": { "ENABLE_SHARED_ELEMENT_TRANSITIONS": true } } を追加し、ネイティブアプリを再ビルドします。この静的フラグはExpo Goでは変更できません。

例

例1: カードスワイプインターフェースの構築

ユーザープロンプト: 「Tinderスタイルのカードスワイプインターフェースをスムーズなアニメーションで構築してください。」

// components/SwipeCard.tsx
import Animated, { interpolate, useAnimatedStyle, useSharedValue, withSpring, withTiming } from "react-native-reanimated";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { scheduleOnRN } from "react-native-worklets";
import { useWindowDimensions } from "react-native";
import type { ReactNode } from "react";

type Props = { children: ReactNode; onSwipe: (direction: "left" | "right") => void };
export function SwipeCard({ children, onSwipe }: Props) {
  const { width } = useWindowDimensions();
  const x = useSharedValue(0);
  const y = useSharedValue(0);
  const pan = Gesture.Pan()
    .onUpdate((e) => { x.value = e.translationX; y.value = e.translationY; })
    .onEnd((e) => {
      if (Math.abs(e.translationX) > width * 0.3) {
        const direction = e.translationX > 0 ? "right" : "left";
        x.value = withTiming(Math.sign(e.translationX) * width * 1.5, { duration: 200 }, (finished) => {
          if (finished) scheduleOnRN(onSwipe, direction);   // Reactのstateでカードを削除
        });
      } else {
        x.value = withSpring(0);
        y.value = withSpring(0);
      }
    });

  const style = useAnimatedStyle(() => ({
    transform: [{ translateX: x.value }, { translateY: y.value }, { rotate: `${interpolate(x.value, [-width, 0, width], [-15, 0, 15])}deg` }],
  }));

  return (
    <GestureDetector gesture={pan}>
      <Animated.View style={style}>{children}</Animated.View>
    </GestureDetector>
  );
}

結果: カードは指の動きに追従し、最大15度回転します。画面幅の30%を超えて離されると飛んでいき、JSスレッドで onSwipe("left" | "right") が実行されます。そうでなければ、中央にスプリングバックします。

例2: アニメーションボトムシート

ユーザープロンプト: 「ドラッグで引き上げることができ、特定の位置にスナップするボトムシートを作成してください。」

// components/BottomSheet.tsx
import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { useWindowDimensions } from "react-native";
import type { ReactNode } from "react";

export function BottomSheet({ children }: { children: ReactNode }) {
  const { height } = useWindowDimensions();
  const snapPoints = [height * 0.1, height * 0.5, height * 0.85]; // 上端: 全開、半分、プレビュー
  const top = useSharedValue(snapPoints[2]);
  const start = useSharedValue(0);
  const pan = Gesture.Pan()
    .onBegin(() => { start.value = top.value; })
    .onUpdate((e) => { top.value = Math.max(snapPoints[0], start.value + e.translationY); })
    .onEnd((e) => {
      const projected = top.value + e.velocityY * 0.2; // フリングで到達する位置
      const target = snapPoints.reduce((a, b) => (Math.abs(b - projected) < Math.abs(a - projected) ? b : a));
      top.value = withSpring(target, { velocity: e.velocityY });
    });

  const style = useAnimatedStyle(() => ({ transform: [{ translateY: top.value }] }));
  const sheet = { position: "absolute", left: 0, right: 0, top: 0, height, backgroundColor: "white" } as const;

  return (
    <GestureDetector gesture={pan}>
      <Animated.View style={[sheet, style]}>{children}</Animated.View>
    </GestureDetector>
  );
}

結果: シートはプレビュー位置から始まり、ドラッグに追従し、離されるとフリングの速度を考慮した上で、最も近い3つのスナップポイントのいずれかにスプリングします。

ガイドライン

  • アニメーション状態には共有値を使用 — useSharedValue はUIスレッド上に存在し、値を変更してもコンポーネントは再レンダリングされません
  • 動的なスタイルには useAnimatedStyle を使用 — UIスレッド上で再計算されます
  • 自然な動きには withSpring を、厳密な時間指定には withTiming を使用 — バージョン4ではスプリングのデフォルト値(ダンピング120、スティフネス900)が変更され、duration は知覚的なものとして扱われます。Reanimated3DefaultSpringConfig を使用すると以前の感覚に戻せます
  • ワークレットからJSを呼び出すには scheduleOnRN を使用 — コンポーネントまたはモジュールスコープで定義された関数を渡します。ワークレット内で作成された関数は渡さないでください
  • Gesture Handlerとの統合 — Gesture.Pan()、Gesture.Pinch() など。インラインで渡されたコールバックは自動的にワークレット化されますが、変数に格納されたコールバックには 'worklet'; ディレクティブが必要です
  • レイアウトアニメーションは宣言的 — Animatedコンポーネントの entering、exiting プロパティで指定します
  • 値のマッピングには interpolate を使用 — スクロール位置を透明度やスケールなどにマッピングします。範囲の終端で停止するには Extrapolation.CLAMP を渡します
  • Worklets Babelプラグインは最後に記述する必要があります — Babel設定を変更した後は、Metroのキャッシュをクリアしてください
  • ワークレット内で大きなオブジェクトをキャプチャしない — キャプチャされた値はUIランタイムにコピーされます。共有値、プリミティブ、小さなプレーンオブジェクトを渡してください
  • 3.xからのアップグレード — 最初に新しいアーキテクチャを有効にし、react-native-worklets をインストールし、Babelプラグインの名前を変更し、削除された useAnimatedGestureHandler、useWorkletCallback、combineTransition を置き換えてください
  • 使用すべきでない場合 — ブロッキングが発生しない単発のフェードやスライドは、React Native組み込みの Animated API(ネイティブのCSSトランジションはReanimated自体から提供されます)のままでも構いません。Reanimated 4は古いアーキテクチャのアプリにはインストールできません

Individual skills in this repo

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

TerminalSkills/skills

>- Run GitHub Actions locally with act. Use when a user asks to test GitHub Actions workflows locally, debug CI pipelines without pushing, or run workflows offline.

TerminalSkills/skills

>- You are an expert in AG2 (formerly AutoGen), the open-source multi-agent conversation framework. You help developers build systems where multiple AI agents collaborate through structured conversations — with tool use, human-in-the-loop, code execution, group chat orchestration, and nested conversations — for complex tasks like software development, research, and data analysis.

TerminalSkills/skills

>- Generate short-form videos with AI — script writing, text-to-speech narration, stock footage selection, subtitle generation, and video assembly. Use when: creating TikTok/YouTube Shorts/Reels content, automating video production, building content pipelines.

TerminalSkills/skills

>- Animate 3D objects and characters in Blender with Python. Use when the user wants to keyframe properties, create armatures and rigs, set up IK/FK chains, animate shape keys for facial animation, edit F-Curves, use the NLA editor to blend actions, add drivers for expression-based animation, or script any animation workflow in Blender.

TerminalSkills/skills

>- Automate motion capture and tracking workflows in Blender with Python. Use when the user wants to import BVH or FBX mocap data, retarget motion to armatures, track camera or object motion from video, solve camera motion, clean up motion capture data, or script any tracking pipeline in Blender.

TerminalSkills/skills

>- You are an expert in Bolt.new by StackBlitz, the AI-powered full-stack development environment that runs entirely in the browser. You help developers go from idea to deployed app in minutes using natural language prompts — Bolt generates complete applications with frontend, backend, database, and deployment, all running in a WebContainer without local setup.

TerminalSkills/skills

>- Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build, javascript runtime, bun runtime.

TerminalSkills/skills

>- Self-host customer support with Chatwoot. Use when a user asks to set up open-source customer support, add live chat without SaaS costs, build a multi-channel inbox, or deploy a free Intercom alternative.

TerminalSkills/skills

>- You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on `net/http`. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

TerminalSkills/skills

When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.

TerminalSkills/skills

>- Add live chat and customer support with Crisp. Use when a user asks to add a chat widget, implement live customer support, set up a help desk, create a knowledge base, or add a chatbot to a website.

TerminalSkills/skills

>- Assists with building custom interactive data visualizations using D3.js. Use when creating charts, graphs, maps, force layouts, or hierarchical diagrams that require fine-grained control beyond what charting libraries provide. Trigger words: d3, data visualization, chart, svg, scales, force graph, treemap, choropleth.

TerminalSkills/skills

dbt (data build tool) transforms data in your warehouse using SQL SELECT statements. Learn project setup, models, tests, documentation, incremental materializations, and integration with data warehouses like PostgreSQL, BigQuery, and Snowflake.

TerminalSkills/skills

>- You are an expert in dlt, the open-source Python library for building data pipelines. You help developers load data from any API, file, or database into warehouses and lakes using simple Python decorators — with automatic schema inference, incremental loading, and built-in data contracts. dlt is the "requests library for data pipelines.

TerminalSkills/skills

Data Version Control for ML projects. Track large datasets and models alongside Git, build reproducible ML pipelines, and run experiments with metric comparison. Works with any storage backend including S3, GCS, Azure, and local filesystems.

TerminalSkills/skills

>- You are an expert in E2B, the cloud platform for running AI-generated code in secure sandboxes. You help developers give AI agents the ability to execute code, install packages, read/write files, and run long processes in isolated cloud environments — each sandbox is a lightweight VM that boots in ~150ms with full Linux, filesystem, and networking.

TerminalSkills/skills

>- Transcode, convert, edit, and process audio and video with FFmpeg. Use when a user asks to convert video formats (webm to mp4, mkv to mp4), extract audio from video, compress video files, trim or cut clips, concatenate videos, add subtitles, create thumbnails, apply filters, change resolution or bitrate, re-encode media, create GIFs from video, add watermarks, normalize audio, stream media, or build automated media processing pipelines.

TerminalSkills/skills

>- Create advanced animations with GSAP. Use when building complex timelines, scroll-driven animations, SVG morphing, text animations, or high-performance web animations beyond CSS capabilities.

TerminalSkills/skills

>- Generate deterministic MP4 videos from HTML, CSS, media, and seekable animations using HeyGen's HyperFrames framework. Use when someone asks to "render HTML to video", "make a video with HyperFrames", "create a programmatic video", "turn an animation into MP4", "build a launch/product video from HTML", "render GSAP/Lottie/Three.js to video", or set up an agent-driven video pipeline. Covers init/preview/render/add/lint/inspect commands, data-* timing attributes, animation adapters, and the component catalog.

TerminalSkills/skills

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

関連スキル