animation-gesture-detector-press — правило для Claude Code
Правило animation-gesture-detector-press для Claude Code переносит анимацию нажатия кнопки React Native в UI-поток, без перехода в JS. Меняет масштаб или прозрачность при нажатии.
MIT ★ 1 216 обновлён 2026-10-24
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settingsЧто делает animation-gesture-detector-press
Правило требует заменить onPressIn и onPressOut у Pressable на GestureDetector с Gesture.Tap() и shared values. Колбэки жестов выполняются в UI-потоке как worklets, поэтому анимация не ждёт JS-поток.
Состояние нажатия храните как 0 или 1 в одном shared value, а масштаб выводите через interpolate — так значение остаётся единственным источником правды. Обычный JS-обработчик вызывайте через runOnJS, а доступ к значению ведите через .set() и .get(): этого требует совместимость с React Compiler.
Оба пакета должны уже стоять в проекте: примеры импортируют react-native-gesture-handler и react-native-reanimated напрямую.
Какие задачи решает
- сделать анимацию нажатия кнопки без задержки на JS-потоке
- перевести масштаб и прозрачность на shared values
- вызвать обычный обработчик нажатия из worklet
- держать состояние нажатия в одном shared value
- сохранить совместимость с React Compiler в анимациях
Примеры запросов агенту
- Перепиши кнопку на
GestureDetectorсGesture.Tap(), чтобы масштаб анимировался в UI-потоке. - Замени
onPressInиonPressOutуPressableна shared value иinterpolate. - Проверь, что обработчик нажатия вызывается через
runOnJS.
Как установить animation-gesture-detector-press
1Через маркетплейс плагинов
/plugin marketplace add fcakyon/claude-codex-settings/plugin install react-skills@claude-settings2Вручную: положить файлы
.claude/rules/animation-gesture-detector-press.mdПоле paths во frontmatter ограничивает файлы
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.cursor/rules/animation-gesture-detector-press.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.github/instructions/animation-gesture-detector-press.instructions.mdПоле applyTo задаёт, к каким файлам применять
Вручную: положить файлы
.devin/rules/animation-gesture-detector-press.mdВручную: положить файлы
.clinerules/animation-gesture-detector-press.mdПо шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать
Вопросы об animation-gesture-detector-press
Как установить animation-gesture-detector-press в Claude Code?
Добавьте маркетплейс командой /plugin marketplace add fcakyon/claude-codex-settings, затем поставьте плагин: /plugin install react-skills@claude-settings. Файл правила окажется по пути .claude/rules/animation-gesture-detector-press.md.
Что делает animation-gesture-detector-press?
Описывает, как строить анимированное нажатие в React Native через GestureDetector и Gesture.Tap() вместо колбэков Pressable, чтобы анимация шла в UI-потоке.
Что нужно для работы правила?
В проекте должны быть react-native-gesture-handler и react-native-reanimated: примеры импортируют их напрямую.
Исходный текст
animation-gesture-detector-press.md · MIT
---
title: Use GestureDetector for Animated Press States
impact: MEDIUM
impactDescription: UI thread animations, smoother press feedback
tags: animation, gestures, press, reanimated
---
## Use GestureDetector for Animated Press States
For animated press states (scale, opacity on press), use `GestureDetector` with
`Gesture.Tap()` and shared values instead of Pressable's
`onPressIn`/`onPressOut`. Gesture callbacks run on the UI thread as worklets—no
JS thread round-trip for press animations.
**Incorrect (Pressable with JS thread callbacks):**
```tsx
import { Pressable } from 'react-native'
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
} from 'react-native-reanimated'
function AnimatedButton({ onPress }: { onPress: () => void }) {
const scale = useSharedValue(1)
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ scale: scale.value }],
}))
return (
<Pressable
onPress={onPress}
onPressIn={() => (scale.value = withTiming(0.95))}
onPressOut={() => (scale.value = withTiming(1))}
>
<Animated.View style={animatedStyle}>
<Text>Press me</Text>
</Animated.View>
</Pressable>
)
}
```
**Correct (GestureDetector with UI thread worklets):**
```tsx
import { Gesture, GestureDetector } from 'react-native-gesture-handler'
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
interpolate,
runOnJS,
} from 'react-native-reanimated'
function AnimatedButton({ onPress }: { onPress: () => void }) {
// Store the press STATE (0 = not pressed, 1 = pressed)
const pressed = useSharedValue(0)
const tap = Gesture.Tap()
.onBegin(() => {
pressed.set(withTiming(1))
})
.onFinalize(() => {
pressed.set(withTiming(0))
})
.onEnd(() => {
runOnJS(onPress)()
})
// Derive visual values from the state
const animatedStyle = useAnimatedStyle(() => ({
transform: [
{ scale: interpolate(withTiming(pressed.get()), [0, 1], [1, 0.95]) },
],
}))
return (
<GestureDetector gesture={tap}>
<Animated.View style={animatedStyle}>
<Text>Press me</Text>
</Animated.View>
</GestureDetector>
)
}
```
Store the press **state** (0 or 1), then derive the scale via `interpolate`.
This keeps the shared value as ground truth. Use `runOnJS` to call JS functions
from worklets. Use `.set()` and `.get()` for React Compiler compatibility.
Reference:
[Gesture Handler Tap Gesture](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/tap-gesture)
© fcakyon · MIT · fcakyon/claude-codex-settings