@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
38 lines (36 loc) • 1.15 kB
JavaScript
import React from 'react';
import Portal from "../portal/index.js";
import ActionSheet from "./action-sheet.js";
import ActionSheetMethod from "./action-sheet-method.js";
import { jsx as _jsx } from "react/jsx-runtime";
export const ActionSheetInstance = opts => {
return new Promise((resolve, reject) => {
const key = Portal.add(/*#__PURE__*/_jsx(ActionSheetMethod, {
...opts,
onClosed: () => {
Portal.remove(key);
opts.onClosed?.();
},
onResponse: (action, item, index) => {
opts.onResponse?.(action, item, index);
// 语义上应该是指定某个操作,不会关系是如何取消的,所以 Promise 只关系点击了哪个操作
if (action === 'item') {
resolve({
item: item,
index: index
});
} else {
reject(new Error(action));
}
}
}));
});
};
export const Component = props => /*#__PURE__*/_jsx(Portal, {
children: /*#__PURE__*/_jsx(ActionSheet, {
...props
})
});
export const ActionSheetComponent = Component;
//# sourceMappingURL=action-sheet-instance.js.map
;