UNPKG

@fruits-chain/react-native-xiaoshu

Version:
74 lines (64 loc) 2.07 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { useState, useEffect, memo } from 'react'; import { callInterceptor } from '../helpers'; import ActionSheet from './action-sheet'; /** * ActionSheet 动作面板 * @description 底部弹起的模态面板,包含与当前情境相关的多个选项。 */ const ActionSheetMethod = _ref => { let { actions, beforeClose, callback, ...restProps } = _ref; const [visible, setVisible] = useState(false); const [localActions, setLocalActions] = useState(() => { return actions.map(ac => { if (typeof ac === 'string') { return { name: ac }; } return ac; }); }); const genOnPressBtn = action => (item, index) => { const canceled = () => { setLocalActions(las => las.map(ac => { if (ac._loading) { ac.loading = false; ac._loading = false; } return ac; })); }; callInterceptor(beforeClose, { args: [action, item, index], done: () => { callback === null || callback === void 0 ? void 0 : callback(action, item, index); canceled(); setVisible(false); }, canceled }); }; useEffect(() => { setVisible(true); }, []); const onRequestClose = () => { genOnPressBtn('overlay')(); return true; }; return /*#__PURE__*/React.createElement(ActionSheet, _extends({}, restProps, { onRequestClose: onRequestClose, visible: visible, actions: localActions, onPressOverlay: genOnPressBtn('overlay'), onCancel: genOnPressBtn('cancel'), onSelect: (item, index) => genOnPressBtn('item')(item, index) })); }; export default /*#__PURE__*/memo(ActionSheetMethod); //# sourceMappingURL=action-sheet-method.js.map