UNPKG

taro-hooks

Version:
40 lines (39 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var taro_1 = require("@tarojs/taro"); var core_1 = require("@taro-hooks/core"); var usePromise_1 = tslib_1.__importDefault(require("../usePromise")); var tool_1 = require("../utils/tool"); function useActionSheet(option) { var generalOption = (0, core_1.useRef)(option); var _ref = (0, core_1.useState)(), tapItem = _ref[0], setTapItem = _ref[1]; (0, core_1.useEffect)(function () { generalOption.current = option; }, [option]); var showActionSheetAsync = (0, usePromise_1["default"])(taro_1.showActionSheet); var show = function show(option) { if (!option && !generalOption.current) return Promise.reject((0, tool_1.generateGeneralFail)('showToast', 'please provide a option')); var actionSheetOption = (0, tool_1.combineOptions)(generalOption.current, option); return showActionSheetAsync(actionSheetOption).then(function (_ref2) { var _actionSheetOption$it; var tapIndex = _ref2.tapIndex; var currentTapItemString = actionSheetOption == null ? void 0 : (_actionSheetOption$it = actionSheetOption.itemList) == null ? void 0 : _actionSheetOption$it[tapIndex]; var currentTapItem = { tapIndex: tapIndex, tapItem: currentTapItemString }; setTapItem(currentTapItem); return currentTapItem; }); }; return { tapItem: tapItem, show: show }; } exports["default"] = useActionSheet;