UNPKG

@wix/design-system

Version:

@wix/design-system

39 lines (38 loc) 1.13 kB
"use strict"; exports.__esModule = true; exports.useHorizontalSwipe = void 0; var _react = require("react"); var useHorizontalSwipe = _ref => { var onSwipe = _ref.onSwipe, _ref$threshold = _ref.threshold, threshold = _ref$threshold === void 0 ? 50 : _ref$threshold, _ref$disabled = _ref.disabled, disabled = _ref$disabled === void 0 ? false : _ref$disabled; var touchStart = (0, _react.useRef)({ x: 0, y: 0 }); var handleTouchStart = event => { if (disabled) return; var touch = event.touches[0]; touchStart.current = { x: touch.clientX, y: touch.clientY }; }; var handleTouchEnd = event => { if (disabled) return; var touch = event.changedTouches[0]; var deltaX = Math.abs(touch.clientX - touchStart.current.x); var deltaY = Math.abs(touch.clientY - touchStart.current.y); if (deltaX > deltaY && deltaX >= threshold) { onSwipe == null || onSwipe(); } }; return { onTouchStart: handleTouchStart, onTouchEnd: handleTouchEnd }; }; exports.useHorizontalSwipe = useHorizontalSwipe; //# sourceMappingURL=useHorizontalSwipe.js.map