UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

54 lines (51 loc) 1.65 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import AppScanner from '@shopgate/pwa-core/classes/Scanner'; import connect from "./connector"; /** * Wraps the Scanner overlay with functionality to automatically open and close the scanner, * as well as triggering the removal and reset of the background. */ let ScannerContainer = /*#__PURE__*/function (_PureComponent) { function ScannerContainer() { return _PureComponent.apply(this, arguments) || this; } _inheritsLoose(ScannerContainer, _PureComponent); var _proto = ScannerContainer.prototype; /** * Starts up the app scanner. */ _proto.componentDidMount = async function componentDidMount() { // Avoid trying to open the scanner if the app does not support it. if (!this.props.hasScannerSupport) { return; } await AppScanner.open(this.props.scope, this.props.type); this.props.scannerDidOpen(); } /** * Shut down the app scanner. */; _proto.componentWillUnmount = function componentWillUnmount() { if (!this.props.hasScannerSupport) { return; } this.props.scannerDidClose(); AppScanner.close(); } /** * Does not render anything when the app does not support the scanner. * @returns {JSX} */; _proto.render = function render() { return this.props.hasScannerSupport && this.props.children; }; return ScannerContainer; }(PureComponent); ScannerContainer.defaultProps = { children: null, scannerDidClose: () => {}, scannerDidOpen: () => {} }; export default connect(ScannerContainer);