React Native Gesture Handler is a declarative API that exposes the native platform's touch and gesture system to React Native applications. It provides a robust and performant way to handle complex gestures like pan, pinch, rotate, and tap directly on the native UI thread, leading to smoother animations and a more responsive user experience compared to JavaScript-based gesture systems. The current stable version is 2.31.1, with an active release cadence that frequently publishes patch and minor updates, and a significant version 3.0 in public beta. Key differentiators include its deep integration with the native UI, enabling seamless interoperability with `react-native-reanimated` for advanced animations, and its move towards a hook-based API in version 3 designed for React Native's New Architecture. It aims to reduce the load on the JavaScript thread by offloading gesture recognition to the native side.
npm install react-native-gesture-handlerVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic tap gesture using the `GestureDetector` and `Gesture` API (v3 style), incrementing a counter on tap. It includes the necessary `GestureHandlerRootView` wrapping the entire application.
Review the official migration guide for v3.0 (once stable) or the beta release blog post. Refactor old gesture handler components (e.g., `PanGestureHandler`) to the new `Gesture` and `GestureDetector` API.
Replace usage of `gestureHandlerRootHOC` with `GestureHandlerRootView`. Wrap your main `App` component or the root of your application with `<GestureHandlerRootView style={{ flex: 1 }}>...</GestureHandlerRootView>`.Ensure your top-level `App` component or the root of your component tree is wrapped within `<GestureHandlerRootView style={{ flex: 1 }}>...</GestureHandlerRootView>`.Always check the changelog for specific React Native version support. For example, v2.31.x supports RN 0.85, and v2.28.0 supports RN 0.81. Ensure your `react-native` and `react-native-gesture-handler` versions are aligned with the project's requirements.
If previously accessing `end` from a different scope or structure within these handlers, adjust your code to destructure it directly from the event object received by `onDeactivate` or `onFinalize`.
Run `npx react-native link react-native-gesture-handler` (for older RN versions, though auto-linking is default now). Try clearing Metro cache (`npx react-native start --reset-cache`), clearing watchman watches (`watchman watch-del-all`), reinstalling node modules and pods (`rm -rf node_modules && yarn install && cd ios && pod install`). For Android, try `cd android && ./gradlew clean`.
Ensure your application's root component is wrapped with `GestureHandlerRootView`. If using v3, verify `GestureDetector` wraps the interactive component. If using v2, ensure `gestureHandlerRootHOC` is applied or the specific `GestureHandler` component (e.g., `PanGestureHandler`) is correctly positioned in the component tree.
Check the changelog for any changes to Touchable components. Ensure `react-native-gesture-handler` and its `@types/react-native` peer dependency are up to date. As of v2.31.1, fixes for Touchables TypeScript errors were applied, suggesting this was a known issue.
Clean your Android project: `cd android && ./gradlew clean`. Ensure your `build.gradle` configuration isn't including `react-native-gesture-handler` multiple times or in conflicting ways. Rebuild the project. Sometimes deleting the `.gradle` folder in the project's root and in `android/.gradle` helps, followed by a full reinstall and `pod install` for iOS.