animation-gesture-detector-press — Claude Code rule
animation-gesture-detector-press is a React Native rule that keeps press animations on the UI thread, for buttons that scale or fade while pressed.
MIT ★ 1,216 updated 2026-10-24
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settingsWhat animation-gesture-detector-press does
Reach for this when a button should scale or fade while pressed. The rule drops the onPressIn/onPressOut pair on Pressable and uses a tap gesture whose callbacks are worklets, so the animation stays on the UI thread and skips a round trip to JS.
Hold the press state in one shared value as 0 or 1, then compute scale with interpolate; the value stays the source of truth. Fire the real handler through runOnJS. Read and write the value with .set() and .get() so React Compiler keeps working.
The snippets import react-native-gesture-handler and react-native-reanimated. Both packages have to be in the project already, since the examples pull from them directly.
What it helps with
- animate a button press on the UI thread
- replace Pressable press callbacks with a tap gesture
- call a JS handler from inside a worklet
- derive scale from a single shared value
- keep shared value access React Compiler safe
Example prompts for the agent
- Rewrite this button with
GestureDetectorandGesture.Tap()so the press animation runs as a worklet. - Swap the
Pressablepress callbacks for a shared value andinterpolate. - Make sure the tap handler fires through
runOnJS.
How to install animation-gesture-detector-press
1Plugin marketplace
/plugin marketplace add fcakyon/claude-codex-settings/plugin install react-skills@claude-settings2Manually: put the files in place
.claude/rules/animation-gesture-detector-press.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/animation-gesture-detector-press.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/animation-gesture-detector-press.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/animation-gesture-detector-press.mdManually: put the files in place
.clinerules/animation-gesture-detector-press.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about animation-gesture-detector-press
How do I install animation-gesture-detector-press in Claude Code?
Run /plugin marketplace add fcakyon/claude-codex-settings, then /plugin install react-skills@claude-settings. The rule lands at .claude/rules/animation-gesture-detector-press.md.
What does animation-gesture-detector-press do?
It sets out how to build an animated press in React Native with GestureDetector and Gesture.Tap() instead of Pressable callbacks, so the animation runs on the UI thread.
What does the rule need to work?
react-native-gesture-handler and react-native-reanimated must already be installed, because the examples import from both.
Source text
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