animating-react-native-expo by tristanmanchester/agent-skills
npx skills add https://github.com/tristanmanchester/agent-skills --skill animating-react-native-expo如果现有代码库已使用不同的模式,请保持一致性,仅在必要时迁移。
npx expo install react-native-reanimated react-native-worklets react-native-gesture-handler
运行设置检查(可选):
node {baseDir}/scripts/check-setup.mjs
withTimingimport { Pressable } from 'react-native';
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
export function FadeInBox() {
const opacity = useSharedValue(0);
const style = useAnimatedStyle(() => ({ opacity: opacity.value }));
return (
<Pressable onPress={() => (opacity.value = withTiming(opacity.value ? 0 : 1, { duration: 200 }))}>
<Animated.View style={[{ width: 80, height: 80 }, style]} />
</Pressable>
);
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
import { GestureDetector, usePanGesture } from 'react-native-gesture-handler';
export function Draggable() {
const x = useSharedValue(0);
const y = useSharedValue(0);
const pan = usePanGesture({
onUpdate: (e) => {
x.value = e.translationX;
y.value = e.translationY;
},
onDeactivate: () => {
x.value = withSpring(0);
y.value = withSpring(0);
},
});
const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }, { translateY: y.value }] }));
return (
<GestureDetector gesture={pan}>
<Animated.View style={[{ width: 100, height: 100 }, style]} />
</GestureDetector>
);
}
import Animated from 'react-native-reanimated';
export function ExpandingCard({ expanded }: { expanded: boolean }) {
return (
<Animated.View
style={{
width: expanded ? 260 : 180,
transitionProperty: 'width',
transitionDuration: 220,
}}
/>
);
}
scheduleOnRN 调用它。useSharedValue。useAnimatedStyle 派生样式。withTiming;物理效果优先使用 withSpring。scheduleOnRN)。usePanGesture、useTapGesture 等)。当样式值因 React 状态/属性改变而需要动画效果时使用。
经验法则:
transitionProperty + transitionDuration。transitionProperty: 'all'(性能 + 意外的动画)。flexDirection)无法平滑过渡;请改用布局动画。当元素进入/退出,或由于条件渲染/回流导致布局变化时使用。
优先使用预设动画(进入/退出、关键帧、布局过渡)。仅当预设无法表达所需运动时,才使用完全自定义的布局动画。
优先使用 Reanimated 滚动处理器/共享值;保持工作单元体量小巧。完整示例请参见:
expo install 安装时,由 babel-preset-expo 处理。react-native-worklets/plugin。GestureHandlerRootView 包裹。scheduleOnRN(fn, ...args)。fn 必须在 JS 作用域中定义(组件体或模块作用域),而不是在工作单元内部创建。transitionProperty: 'all'。scheduleOnUI/scheduleOnRN,闭包捕获,迁移说明。grep -Rni "scheduleOnRN" {baseDir}/references
grep -Rni "transitionProperty" {baseDir}/references
grep -Rni "usePanGesture" {baseDir}/references
每周安装量
92
代码仓库
首次出现
2026年2月9日
安全审计
安装于
gemini-cli91
codex91
opencode91
cursor91
kimi-cli90
amp90
If an existing codebase already uses a different pattern, stay consistent and only migrate when necessary.
npx expo install react-native-reanimated react-native-worklets react-native-gesture-handler
Run the setup check (optional):
node {baseDir}/scripts/check-setup.mjs
withTimingimport { Pressable } from 'react-native';
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
export function FadeInBox() {
const opacity = useSharedValue(0);
const style = useAnimatedStyle(() => ({ opacity: opacity.value }));
return (
<Pressable onPress={() => (opacity.value = withTiming(opacity.value ? 0 : 1, { duration: 200 }))}>
<Animated.View style={[{ width: 80, height: 80 }, style]} />
</Pressable>
);
}
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
import { GestureDetector, usePanGesture } from 'react-native-gesture-handler';
export function Draggable() {
const x = useSharedValue(0);
const y = useSharedValue(0);
const pan = usePanGesture({
onUpdate: (e) => {
x.value = e.translationX;
y.value = e.translationY;
},
onDeactivate: () => {
x.value = withSpring(0);
y.value = withSpring(0);
},
});
const style = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }, { translateY: y.value }] }));
return (
<GestureDetector gesture={pan}>
<Animated.View style={[{ width: 100, height: 100 }, style]} />
</GestureDetector>
);
}
import Animated from 'react-native-reanimated';
export function ExpandingCard({ expanded }: { expanded: boolean }) {
return (
<Animated.View
style={{
width: expanded ? 260 : 180,
transitionProperty: 'width',
transitionDuration: 220,
}}
/>
);
}
scheduleOnRN.useSharedValue for numbers/strings/objects that must be read/written from both UI and JS.useAnimatedStyle.withTiming for UI tweens; withSpring for physics.scheduleOnRN).See: references/worklets-and-threading.md
usePanGesture, useTapGesture, etc.).Use when a style value changes due to React state/props and you just want it to animate.
Rules of thumb:
transitionProperty + transitionDuration.transitionProperty: 'all' (perf + surprise animations).flexDirection) won’t transition smoothly; use Layout Animations instead.See: references/css-transitions-and-animations.md
Use when elements enter/exit, or when layout changes due to conditional rendering/reflow.
Prefer presets first (entering/exiting, keyframes, layout transitions). Only reach for fully custom layout animations when presets can’t express the motion.
See: references/layout-animations.md
Prefer Reanimated scroll handlers/shared values; keep worklet bodies tiny. For full recipes, see:
babel-preset-expo when installed via expo install.react-native-worklets/plugin.GestureHandlerRootView.scheduleOnRN(fn, ...args).fn must be defined in JS scope (component body or module scope), not created inside a worklet.transitionProperty: 'all'.See: references/debugging-and-performance.md
scheduleOnUI/scheduleOnRN, closure capture, migration notes.grep -Rni "scheduleOnRN" {baseDir}/references
grep -Rni "transitionProperty" {baseDir}/references
grep -Rni "usePanGesture" {baseDir}/references
Weekly Installs
92
Repository
First Seen
Feb 9, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
gemini-cli91
codex91
opencode91
cursor91
kimi-cli90
amp90
React Native 棕地迁移指南:逐步集成到原生应用(Expo/裸RN)
517 周安装
ByteRover CLI - 上下文工程平台,为AI编码智能体自动管理项目知识库
154 周安装
嵌入式系统开发指南:RTOS、裸机固件、嵌入式Linux与微控制器编程实战
155 周安装
Markdown转EPUB转换器 - 专业电子书制作工具,支持代码高亮与表格样式
158 周安装
化学品安全与毒理学评估工具 | AI预测毒理学、ADMET分析、基因互作与监管安全数据整合
156 周安装
gentle-teaching 温和教学框架:AI辅助学习指南,培养独立解决问题能力
156 周安装
iOS应用可发现性优化指南:通过App Intents、App Shortcuts和Core Spotlight提升应用曝光
157 周安装