@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
21 lines • 1.73 kB
JavaScript
import hideMenuBar from'@shopgate/pwa-core/commands/hideMenuBar';import broadcastEvent from'@shopgate/pwa-core/commands/broadcastEvent';import showTab from'@shopgate/pwa-core/commands/showTab';import{appSupportsAndroidEdgeToEdge}from'@shopgate/engage/core/helpers';/**
* Page context that comes from the app.
* @type {Object}
*/var currentPageContext={};/**
* Get Page context if available.
* @returns {Object}
*/export var getPageContext=function getPageContext(){return currentPageContext;};/**
* Prepares the NavigationBar and the MenuBar of the app legacy part for the PWA.
*/export var prepareLegacyNavigation=function prepareLegacyNavigation(){// Logic below causes issues on Android app with edge-to-edge screens. For compatibility reasons
// logic is skipped for now on those devices. Function could potentially be removed in the future.
if(appSupportsAndroidEdgeToEdge()){return;}/**
* Broadcasts an event to the pwa_navigation_bar webview and updates the navigation bar with
* type "none". Event parameters are defined accordingly to the specification of the native
* updateNavigationBar event.
*/broadcastEvent({event:'updateNavigationBar',parameters:['','none',{type:'none'}]});hideMenuBar({animation:null});};/**
* Shows the main tab when legacy system requests the previous tab.
* @param {Object} context The page context from the app.
* @param {string} context.tab The tab where the page is opened.
*/export var pageContext=function pageContext(context){currentPageContext=context;};/**
* Shows the main tab when legacy system requests the previous tab.
*/export var showPreviousTab=function showPreviousTab(){showTab({targetTab:currentPageContext.tab?currentPageContext.tab:'main'});};