UNPKG

@td-design/react-native

Version:

react-native UI组件库

36 lines 1.37 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 from 'react'; import { useSafeState } from '@td-design/rn-hooks'; import Portal from '../../portal'; import ModalView from '../Modal/ModalView'; export default function show(comp, props) { const key = Portal.add( /*#__PURE__*/React.createElement(ModalContent, _extends({}, props, { onAnimationEnd: visible => { if (!visible) { Portal.remove(key); } } }), comp)); } const ModalContent = _ref => { let { children, ...props } = _ref; const [visible, setVisible] = useSafeState(true); return /*#__PURE__*/React.createElement(ModalView, _extends({ position: "center", maskVisible: true, maskClosable: true, animationType: "slide" }, props, { visible: visible, onClose: () => setVisible(false) }), /*#__PURE__*/React.isValidElement(children) ? /*#__PURE__*/React.cloneElement(children, { // Add any props you want to pass to the child here closeModal() { setVisible(false); } }) : null); }; //# sourceMappingURL=index.js.map