@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
86 lines (85 loc) • 3.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _index2 = require("../helpers/index.js");
var _index3 = require("../hooks/index.js");
var _actionSheet = _interopRequireDefault(require("./action-sheet.js"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* ActionSheet 动作面板
* @description 底部弹起的模态面板,包含与当前情境相关的多个选项。
*/
const ActionSheetMethod = ({
actions,
beforeClose,
onResponse,
...restProps
}) => {
const [visible, setVisible] = (0, _react.useState)(false);
const [localActions, setLocalActions] = (0, _react.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;
}));
}
(0, _index2.callInterceptor)(beforeClose, {
args: [action, item, index],
done: () => {
canceled();
setVisible(false);
onResponse?.(action, item, index);
},
canceled
});
};
(0, _react.useEffect)(() => {
setVisible(true);
}, []);
const onRequestClose = (0, _index3.usePersistFn)(() => {
genOnPressBtn('overlay')();
return true;
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_actionSheet.default, {
...restProps,
onRequestClose: onRequestClose,
visible: visible,
actions: localActions,
onPressOverlay: genOnPressBtn('overlay'),
onCancel: genOnPressBtn('cancel'),
onSelect: (item, index) => genOnPressBtn('item')(item, index)
});
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(ActionSheetMethod);
//# sourceMappingURL=action-sheet-method.js.map
;