UNPKG

@fruits-chain/react-native-xiaoshu

Version:
79 lines (78 loc) 2.06 kB
"use strict"; import React, { useState, useEffect, memo } from 'react'; import { callInterceptor } from "../helpers/index.js"; import { usePersistFn } from "../hooks/index.js"; import ActionSheet from "./action-sheet.js"; import { jsx as _jsx } from "react/jsx-runtime"; /** * ActionSheet 动作面板 * @description 底部弹起的模态面板,包含与当前情境相关的多个选项。 */ const ActionSheetMethod = ({ actions, beforeClose, onResponse, ...restProps }) => { 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; })); }; if (action === 'item') { setLocalActions(las => las.map((ac, _index) => { if (_index === index) { return { ...ac, loading: true, _loading: true }; } return ac; })); } callInterceptor(beforeClose, { args: [action, item, index], done: () => { canceled(); setVisible(false); onResponse?.(action, item, index); }, canceled }); }; useEffect(() => { setVisible(true); }, []); const onRequestClose = usePersistFn(() => { genOnPressBtn('overlay')(); return true; }); return /*#__PURE__*/_jsx(ActionSheet, { ...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