Skip to main content
rule CX Codex

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

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add fcakyon/claude-codex-settings
/plugin install react-skills@claude-settings
Open on GitHub

What 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 GestureDetector and Gesture.Tap() so the press animation runs as a worklet.
  • Swap the Pressable press callbacks for a shared value and interpolate.
  • 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-settings

2Manually: put the files in place

.claude/rules/animation-gesture-detector-press.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set113

The whole set →
bundle-analyzable-paths The bundle-analyzable-paths rule recommends making import and file paths statically analyzable. That keeps bundlers from treating a broad set of files as reachable. CX Codex +1 ★ 1,216repo stars list-performance-item-expensive The list-performance-item-expensive rule bans heavy list rows: data queries, extra hooks and React Context reads inside renderItem. CX Codex +1 ★ 1,216repo stars ui-image-gallery ui-image-gallery directs AI assistants to build image galleries using @nandorojo/galeria instead of custom modal popups. CX Codex +1 ★ 1,216repo stars rendering-resource-hints The rendering-resource-hints rule tells the agent when to call React DOM's resource-hint functions inside React components. It targets server components, letting the browser start fetching assets before the client even has the HTML. CX Codex +1 ★ 1,216repo stars commit-staged commit-staged automates commit creation: checks staged diffs, runs /simplify on code edits, and writes conventional commits using session rationale. CX Codex +1 ★ 1,216repo stars shell-and-workflows The shell-and-workflows rule documents Docker commands for the project and explains where to run frontend and backend tests. Use it when managing services or checking a change. CX Codex +1 ★ 1,216repo stars js-request-idle-callback js-request-idle-callback — a rule that moves analytics, state saving and prefetching into idle browser time so the interface stops stuttering on every click. CX Codex +1 ★ 1,216repo stars pr-comment-resolver pr-comment-resolver inspects unresolved pull request reviews, applies necessary code updates, and drafts replies for reviewers. Ideal for clearing PR feedback without manual issue hunting. CX Codex ★ 1,216repo stars

Project sponsors

Companies that keep this analytics open