@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
40 lines (34 loc) • 1.57 kB
JavaScript
function _extends() { _extends = Object.assign || 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, { memo, createRef } from 'react';
import Portal from '../portal';
import NotifyView from './notify';
import NotifyMethod from './notify-method';
const Notify = options => {
const opts = typeof options === 'string' ? {
message: options
} : options;
const NotifyRef = /*#__PURE__*/createRef();
const key = Portal.add( /*#__PURE__*/React.createElement(NotifyMethod, _extends({}, opts, {
ref: NotifyRef,
onClosed: () => {
var _opts$onClosed;
Portal.remove(key);
(_opts$onClosed = opts.onClosed) === null || _opts$onClosed === void 0 ? void 0 : _opts$onClosed.call(opts);
}
})));
return {
close: () => {
var _NotifyRef$current;
(_NotifyRef$current = NotifyRef.current) === null || _NotifyRef$current === void 0 ? void 0 : _NotifyRef$current.close();
},
setMessage: m => {
var _NotifyRef$current2;
(_NotifyRef$current2 = NotifyRef.current) === null || _NotifyRef$current2 === void 0 ? void 0 : _NotifyRef$current2.setMessage(m);
}
};
};
Notify.Component = /*#__PURE__*/memo(props => {
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(NotifyView, props));
});
export default Notify;
//# sourceMappingURL=index.js.map