UNPKG

react-native-graph-plus

Version:

📈 Beautiful, high-performance Graphs and Charts for React Native +

27 lines • 879 B
import { useMemo } from 'react'; import { Gesture } from 'react-native-gesture-handler'; import { useSharedValue } from 'react-native-reanimated'; export function usePanGesture(_ref) { let { enabled, holdDuration = 300 } = _ref; const x = useSharedValue(0); const y = useSharedValue(0); const isPanGestureActive = useSharedValue(false); const panGesture = useMemo(() => Gesture.Pan().enabled(enabled).activateAfterLongPress(holdDuration).onChange(e => { x.value = e.x; y.value = e.y; }).onStart(() => { isPanGestureActive.value = true; }).onEnd(() => { isPanGestureActive.value = false; }), [enabled, holdDuration, isPanGestureActive, x, y]); return useMemo(() => ({ gesture: panGesture, isActive: isPanGestureActive, x: x, y: y }), [isPanGestureActive, panGesture, x, y]); } //# sourceMappingURL=usePanGesture.js.map