@ant-design/react-native
Version:
基于蚂蚁金服移动设计规范的 React Native 组件库
1 lines • 1.21 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});exports.default=useClickAway;exports.CustomSyntheticEvent=exports.USE_CLICK_AWAY_EVENT_NAME=void 0;var _react=require("react");var _reactNative=require("react-native");var USE_CLICK_AWAY_EVENT_NAME='ANT_DESIGN_MOBILE_RN_USE_CLICK_AWAY';exports.USE_CLICK_AWAY_EVENT_NAME=USE_CLICK_AWAY_EVENT_NAME;var TopViewEventEmitter=_reactNative.DeviceEventEmitter||new _reactNative.NativeEventEmitter();var _temp_bool;var CustomSyntheticEvent={stopPropagation:function stopPropagation(){_temp_bool=true;},preventDefault:function preventDefault(){_temp_bool=undefined;},isPropagationStopped:function isPropagationStopped(){return _temp_bool;},emit:function emit(event){TopViewEventEmitter.emit(USE_CLICK_AWAY_EVENT_NAME,event);}};exports.CustomSyntheticEvent=CustomSyntheticEvent;function useClickAway(onClickAway){var onClickAwayRef=(0,_react.useRef)();(0,_react.useEffect)(function(){onClickAwayRef.current=TopViewEventEmitter.addListener(USE_CLICK_AWAY_EVENT_NAME,onClickAway);return function(){var _a,_b;(_b=(_a=onClickAwayRef.current)===null||_a===void 0?void 0:_a.remove)===null||_b===void 0?void 0:_b.call(_a);};},[onClickAway]);return[CustomSyntheticEvent];}