UNPKG

react-native-alert-notification

Version:
104 lines (83 loc) 3.52 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); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import * as React from 'react'; import { SafeAreaInsetsContext } from 'react-native-safe-area-context'; import { ToastRender } from './ToastRender'; //export type IModelFunc = (args: { isDark: boolean; type?: ALERT_TYPE; title?: string; description?: string }) => ReactElement; export class Toast extends React.Component { /** * @type {React.RefObject<Toast>} */ /** * @param {IConfigToast} args */ /** * */ constructor(props) { super(props); _defineProperty(this, "_open", async data => { var _this$state$data, _this$state$data$onSh; const { titleStyle, textBodyStyle } = this.props.config || {}; const timeout = typeof data.autoClose === 'number' ? data.autoClose : data.autoClose === false ? 0 : 5000; await new Promise(resolve => this.setState(prevState => ({ ...prevState, data: { titleStyle, textBodyStyle, ...data, description: data.textBody, timeout } }), resolve)); (_this$state$data = this.state.data) === null || _this$state$data === void 0 ? void 0 : (_this$state$data$onSh = _this$state$data.onShow) === null || _this$state$data$onSh === void 0 ? void 0 : _this$state$data$onSh.call(_this$state$data); }); _defineProperty(this, "_close", async () => { this._closedHandler(); }); _defineProperty(this, "_closedHandler", async () => { var _this$state$data2; const onHide = (_this$state$data2 = this.state.data) === null || _this$state$data2 === void 0 ? void 0 : _this$state$data2.onHide; await new Promise(resolve => this.setState(prevState => ({ ...prevState, data: null }), resolve)); onHide === null || onHide === void 0 ? void 0 : onHide(); }); this.state = { data: null }; } /** * @param {IConfigToast} args * @return {Promise<void>} */ render() { const { data } = this.state; if (!data) { return null; } const { isDark, config: configGeneral } = this.props; return /*#__PURE__*/React.createElement(SafeAreaInsetsContext.Consumer, null, insets => /*#__PURE__*/React.createElement(ToastRender, _extends({}, data, { isDark: isDark, paddingTop: insets === null || insets === void 0 ? void 0 : insets.top, configGeneral: configGeneral, onClose: this._closedHandler }))); } } _defineProperty(Toast, "instance", /*#__PURE__*/React.createRef()); _defineProperty(Toast, "show", args => { var _Toast$instance$curre; (_Toast$instance$curre = Toast.instance.current) === null || _Toast$instance$curre === void 0 ? void 0 : _Toast$instance$curre._open(args); }); _defineProperty(Toast, "hide", () => { var _Toast$instance$curre2; (_Toast$instance$curre2 = Toast.instance.current) === null || _Toast$instance$curre2 === void 0 ? void 0 : _Toast$instance$curre2._close(); }); //# sourceMappingURL=Toast.js.map