react-native-alert-notification
Version:
Toast notification and dialog box notification for react native
119 lines (91 loc) • 4.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Toast = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _ToastRender = require("./ToastRender");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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; }
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(_reactNativeSafeAreaContext.SafeAreaInsetsContext.Consumer, null, insets => /*#__PURE__*/React.createElement(_ToastRender.ToastRender, _extends({}, data, {
isDark: isDark,
paddingTop: insets === null || insets === void 0 ? void 0 : insets.top,
configGeneral: configGeneral,
onClose: this._closedHandler
})));
}
}
exports.Toast = Toast;
_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
;