gesture-handler-3-migration

Migrates files containing React Native components which use the React Native Gesture Handler 2 API to Gesture Handler 3.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "gesture-handler-3-migration" with this command: npx skills add software-mansion/react-native-gesture-handler/software-mansion-react-native-gesture-handler-gesture-handler-3-migration

Migrate to Gesture Handler 3

This skill scans React Native components that use the Gesture Handler builder-based API and updates them to use the new hook-based API. It also updates related types and components to adapt to the new version.

When to Use

  • Updating the usage of components imported from react-native-gesture-handler
  • Upgrading to Gesture Handler 3
  • Migrating to the new hook-based gesture API

Instructions

Use the instructions below to correctly replace all legacy APIs with the modern ones.

  1. Identify all imports from 'react-native-gesture-handler'
  2. For each Gesture.X() call, replace with corresponding useXGesture() hook
  3. Replace Gesture import with imports for the used hooks
  4. Convert builder method chains to configuration objects
  5. Update callback names (onStart → onActivate, etc.)
  6. Replace composed gestures with relation hooks. Keep rules of hooks in mind
  7. Update GestureDetector usage if SVG is involved to Intercepting/Virtual GestureDetector
  8. Update usage of compoenent imported from 'react-native-gesture-handler' according to "Legacy components" section

Migrating gestures

All hook gestures have their counterparts in the builder API: Gesture.X() becomes useXGesture(config). The methods are now config object fields with the same name as the relevant builder methods, unless specified otherwise.

The exception to thait is Gesture.ForceTouch which DOES NOT have a counterpart in the hook API.

Callback changes

In Gesture Handler 3 some of the callbacks were renamed, namely:

  • onStart -> onActivate
  • onEnd -> onDeactivate
  • onTouchesCancelled -> onTouchesCancel

In the hooks API onChange is no longer available. Instead the *change* properties were moved to the event available inside onUpdate.

All callbacks of a gesture are now using the same type:

  • usePanGesture() -> PanGestureEvent
  • useTapGesture() -> TapGestureEvent
  • useLongPressGesture() -> LongPressGestureEvent
  • useRotationGesture() -> RotationGestureEvent
  • usePinchGesture() -> PinchGestureEvent
  • useFlingGesture() -> FlingGestureEvent
  • useHoverGesture() -> HoverGestureEvent
  • useNativeGesture() -> RotationGestureEvent
  • useManualGesture() -> ManualGestureEvent

The exception to this is touch events:

  • onTouchesDown
  • onTouchesUp
  • onTouchesMove
  • onTouchesCancel

Where each callback receives GestureTouchEvent regardless of the hook used.

StateManager

In Gesture Handler 3, stateManager is no longer passed to TouchEvent callbacks. Instead, you should use the global GestureStateManager.

GestureStateManager provides methods for imperative state management:

  • .begin(handlerTag: number)
  • .activate(handlerTag: number)
  • .deactivate(handlerTag: number) (.end() in the old API)
  • .fail(handlerTag: number)

handlerTag can be obtained in two ways:

  1. From the gesture object returned by the hook (gesture.handlerTag)
  2. From the event inside callback (event.handlerTag)

Callback definitions CANNOT reference the gesture that's being defined. In this scenario use events to get access to the handler tag.

Migrating relations

Composed gestures

Gesture.Simultaneous(gesture1, gesture2); becomes useSimultaneousGestures(pan1, pan2);

All relations from the old API and their counterparts in the new one:

  • Gesture.Race() -> useCompetingGestures()
  • Gesture.Simultaneous() -> useSimultaneousGestures()
  • Gesture.Exclusive() -> useExclusiveGestures()

Cross components relations properties

Properties used to define cross-components interactions were renamed:

  • .simultaneousWithExternalGesture -> simultaneousWith:
  • .requireExternalGestureToFail -> requireToFail:
  • .blocksExternalGesture -> block:

GestureDetector

The GestureDetector is a key component of react-native-gesture-handler. It supports gestures created either using the hooks API or the builder pattern (but those cannot be mixed, it's either or).

Don't use the same instance of a gesture across multiple Gesture Detectors as it will lead to an undefined behavior.

Integration with Reanimated

Worklets' Babel plugin is setup in a way that automatically marks callbacks passed to gestures in the configuration chain as worklets. This means that you don't need to add a 'worklet'; directive at the beginning of the functions.

This will not be workletized because the callback is defined outside of the gesture object:

const callback = () => {
  console.log(_WORKLET);
};

const gesture = useTapGesture({
  onBegin: callback,
});

The callback wrapped by any other higher order function will not be workletized:

const gesture = useTapGesture({
  onBegin: useCallback(() => {
    console.log(_WORKLET);
  }, []),
});

In the above cases, you should add a "worklet"; directive as the first line of the callback.

Disabling Reanimated

Gestures created with the hook API have Reanimated integration enabled by default (if it's installed), meaning all callbacks are executed on the UI thread.

runOnJS

The runOnJS property allows you to dynamically control whether callbacks are executed on the JS thread or the UI thread. When set to true, callbacks will run on the JS thread. Setting it to false will execute them on the UI thread. Default value is false.

Migrating components relying on view hierarchy

Certain components, such as SVG, depend on the view hierarchy to function correctly. In Gesture Handler 3, GestureDetector disrupts these hierarchies. To resolve this issue, two new detectors have been introduced: InterceptingGestureDetector and VirtualGestureDetector.

InterceptingGestureDetector functions similarly to the GestureDetector, but it can also act as a proxy for VirtualGestureDetector within its component subtree. Because it can be used solely to establish the context for virtual detectors, the gesture property is optional.

VirtualGestureDetector is similar to the GestureDetector from RNGH2. Because it is not a host component, it does not interfere with the host view hierarchy. This allows you to attach gestures without disrupting functionality that depends on it.

Warning: VirtualGestureDetector has to be a descendant of InterceptingGestureDetector.

Migrating SVG

In Gesture Handler 2 it was possible to use GestureDetector directly on SVG. In Gesture Handler 3, the correct way to interact with SVG is to use InterceptingGestureDetector and VirtualGestureDetector.

Legacy components

When the code using the component relies on the APIs that are no longer available on the components in Gesture Handler 3 (like waitFor, simultaneousWith, blocksHandler, onHandlerStateChange, onGestureEvent props), it cannot be easily migrated in isolation. In this case update the imports to the Legacy version of the component, and inform the user that the dependencies need to be migrated first.

If the migration is possible, use the ask questions tool to clarify the user intent unless clearly stated beforehand: should the components be using the new implementation (no Legacy prefix when imported), or should they revert to the old implementation (Legacy prefix when imported)?

Don't suggest replacing buttons from Gesture Handler with components from React Native and vice versa.

The implementation of buttons has been updated, resolving most button-related issues. They have also been internally rewritten to utilize the new hook API. The legacy JS implementations of button components are still accessible but have been renamed with the prefix Legacy, e.g., RectButton is now available as LegacyRectButton. Those still use the new native component under the hood.

PureNativeButton has been removed. If encountered, inform the user that it has been removed and let them decide how to handle that case. They can achieve similar functionality with other buttons.

Other components have also been internally rewritten using the new hook API but are exported under their original names, so no changes are necessary on your part. However, if you need to use the previous implementation for any reason, the legacy components are also available and are prefixed with Legacy, e.g., ScrollView is now available as LegacyScrollView.

Rename all instances of createNativeWrapper to legacy_createNativeWrapper. This includes both the import statements and the function calls.

Replaced types

Most of the types used in the builder API, like TapGesture, are still present in Gesture Handler 3. However, they are now used in new hook API. Types for builder API now have Legacy prefix, e.g. TapGesture becomes LegacyTapGesture.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

问专家 - Playwriter模式

# 问专家技能 - 使用 Playwriter 控制已登录的浏览器

Archived SourceRecently Updated
General

ai-image-generator

AI 图片与视频异步生成技能,调用 AI Artist API 根据文本提示词生成图片或视频,自动轮询直到任务完成。 ⚠️ 使用前必须设置环境变量 AI_ARTIST_TOKEN 为你自己的 API Key! 获取 API Key:访问 https://staging.kocgo.vip/index 注册登录后创建。 支持图片模型:SEEDREAM5_0(默认高质量图片)、NANO_BANANA_2(轻量快速)。 支持视频模型:SEEDANCE_1_5_PRO(文生视频,支持音频)、SORA2(文生视频或首尾帧图生视频,支持 firstImageUrl/lastImageUrl)。 触发场景: - 用户要求生成图片,如"生成一匹狼"、"画一只猫"、"风景画"、"帮我画"等。 - 用户要求生成视频,如"生成视频"、"用 SORA2 生成"、"文生视频"、"图生视频"、"生成一段...的视频"等。 - 用户指定模型:SEEDREAM5_0、NANO_BANANA_2、SEEDANCE_1_5_PRO、SORA2。

Archived SourceRecently Updated
General

淘宝投放数据分析

# 投放数据分析技能

Archived SourceRecently Updated
General

productclank-campaigns

Community-powered growth for builders. Boost amplifies your social posts with authentic community engagement (replies, likes, reposts). Discover finds relevant conversations and generates AI-powered replies at scale. Use Boost when the user has a post URL. Use Discover when the user wants to find and engage in conversations about their product.

Archived SourceRecently Updated