@ant-design/react-native
Version:
基于蚂蚁金服移动设计规范的 React Native 组件库
1 lines • 1.4 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});exports.default=useClickAway;exports.CustomSyntheticEvent=void 0;var _react=require("react");var CustomSyntheticEvent={stopPropagation:function stopPropagation(){},preventDefault:function preventDefault(){},isPropagationStopped:function isPropagationStopped(){return true;},emit:function emit(){}};exports.CustomSyntheticEvent=CustomSyntheticEvent;function useClickAway(onClickAway){var isDragging=(0,_react.useRef)(false);var shouldRespond=(0,_react.useRef)(true);var listener=(0,_react.useCallback)(function(){if(shouldRespond.current){onClickAway();}else{shouldRespond.current=true;}},[onClickAway]);var onMousedown=function onMousedown(){isDragging.current=true;};var onMousemove=function onMousemove(){if(isDragging.current&&shouldRespond.current){shouldRespond.current=false;}};var onMouseup=function onMouseup(){isDragging.current=false;};(0,_react.useEffect)(function(){document.addEventListener('mousedown',onMousedown);document.addEventListener('mousemove',onMousemove);document.addEventListener('mouseup',onMouseup);document.addEventListener('click',listener);return function(){document.removeEventListener('mousedown',onMousedown);document.removeEventListener('mousemove',onMousemove);document.removeEventListener('mouseup',onMouseup);document.removeEventListener('click',listener);};},[listener]);return[CustomSyntheticEvent];}