Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* eslint-disable react/no-unused-prop-types */
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import { Platform } from 'react-native';
import React, { useEffect, useMemo, useRef } from 'react';
import findNodeHandle from '../../../findNodeHandle';
import { GestureType } from '../gesture';
import { UserSelect, TouchAction } from '../../gestureHandlerCommon';
import { ComposedGesture } from '../gestureComposition';
import { isTestEnv } from '../../../utils';

import GestureHandlerRootViewContext from '../../../GestureHandlerRootViewContext';
import { AttachedGestureState, GestureDetectorState } from './types';
import { useAnimatedGesture } from './useAnimatedGesture';
import { attachHandlers } from './attachHandlers';
Expand Down Expand Up @@ -87,13 +83,6 @@ export interface GestureDetectorProps {
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector
*/
export const GestureDetector = (props: GestureDetectorProps) => {
const rootViewContext = useContext(GestureHandlerRootViewContext);
if (__DEV__ && !rootViewContext && !isTestEnv() && Platform.OS !== 'web') {
throw new Error(
'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation for more details.'
);
}

// Gesture config should be wrapped with useMemo to prevent unnecessary re-renders
const gestureConfig = props.gesture;
propagateDetectorConfig(props, gestureConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import {
import { DetectorContext } from './LogicDetector/useDetectorContext';
import { LogicDetector } from './LogicDetector/LogicDetector';
import { use } from 'react';
import { isTestEnv } from '../../utils';
import { Platform } from 'react-native';
import GestureHandlerRootViewContext from '../../GestureHandlerRootViewContext';

export function GestureDetector<THandlerData, TConfig>(
props: NativeDetectorProps<THandlerData, TConfig> | LegacyGestureDetectorProps
) {
const rootViewContext = use(GestureHandlerRootViewContext);

if (__DEV__ && !rootViewContext && !isTestEnv() && Platform.OS !== 'web') {
throw new Error(
'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation for more details.'
);
}

if (
props.gesture instanceof ComposedGesture ||
props.gesture instanceof BaseGesture
Expand Down
Loading