UNPKG

@shopgate/engage

Version:
86 lines (82 loc) 2.46 kB
import _createClass from "@babel/runtime/helpers/createClass"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import appConfig from '@shopgate/pwa-common/helpers/config'; import { APP_EVENT_VIEW_WILL_APPEAR, APP_EVENT_VIEW_WILL_DISAPPEAR } from '@shopgate/pwa-core/constants/AppEvents'; import event from '@shopgate/pwa-core/classes/Event'; import AppContext from "../contexts/AppContext"; /** * The AppProvider component. */ import { jsx as _jsx } from "react/jsx-runtime"; let AppProvider = /*#__PURE__*/function (_Component) { /** * @param {Object} props The component props. */ function AppProvider(props) { var _this; _this = _Component.call(this, props) || this; /** * Sets the isVisible state to TRUE. */ _this.setVisible = () => { _this.setIsVisible(true); }; /** * Sets the isVisible state to TRUE. */ _this.setHidden = () => { _this.setIsVisible(false); }; _this.state = { isVisible: true }; event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, _this.setVisible); event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, _this.setHidden); return _this; } /** * Removes the event listeners when the component unmounts. */ _inheritsLoose(AppProvider, _Component); var _proto = AppProvider.prototype; _proto.componentWillUnmount = function componentWillUnmount() { event.removeCallback(APP_EVENT_VIEW_WILL_APPEAR, this.setVisible); event.removeCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, this.setHidden); } /** * Returns the context value to be passed to consumers. * @returns {Object} */; /** * Sets the isVisible state. It indicates if Engage is visible, * or another WebView is presented to the user. * @param {boolean} value The new value */ _proto.setIsVisible = function setIsVisible(value) { this.setState({ isVisible: value }); } /** * @returns {JSX} */; _proto.render = function render() { return /*#__PURE__*/_jsx(AppContext.Provider, { value: this.provided, children: this.props.children }); }; return _createClass(AppProvider, [{ key: "provided", get: function () { return { appConfig, isVisible: this.state.isVisible, setIsVisible: this.setIsVisible }; } }]); }(Component); export default AppProvider;