MOBILE-4081 mainmenu: Don't change tab on resize

main
Dani Palou 2022-12-05 10:43:07 +01:00
parent 72c3938ba8
commit 797b2a3690
1 changed files with 15 additions and 8 deletions

View File

@ -118,10 +118,10 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
this.updateVisibility(); this.updateVisibility();
this.subscription = CoreMainMenuDelegate.getHandlersObservable().subscribe((handlers) => { this.subscription = CoreMainMenuDelegate.getHandlersObservable().subscribe((handlers) => {
// Remove the handlers that should only appear in the More menu. const previousHandlers = this.allHandlers;
this.allHandlers = handlers; this.allHandlers = handlers;
this.updateHandlers(); this.updateHandlers(previousHandlers);
}); });
this.badgeUpdateObserver = CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, (data) => { this.badgeUpdateObserver = CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, (data) => {
@ -154,8 +154,10 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
/** /**
* Update handlers on change (size or handlers). * Update handlers on change (size or handlers).
*
* @param previousHandlers Previous handlers (if they haave just been updated).
*/ */
async updateHandlers(): Promise<void> { async updateHandlers(previousHandlers?: CoreMainMenuHandlerToDisplay[]): Promise<void> {
if (!this.allHandlers) { if (!this.allHandlers) {
return; return;
} }
@ -167,7 +169,6 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
.slice(0, CoreMainMenu.getNumItems()); // Get main handlers. .slice(0, CoreMainMenu.getNumItems()); // Get main handlers.
// Re-build the list of tabs. If a handler is already in the list, use existing object to prevent re-creating the tab. // Re-build the list of tabs. If a handler is already in the list, use existing object to prevent re-creating the tab.
const previousTabs = this.tabs.map(tab => tab.page);
const newTabs: CoreMainMenuHandlerToDisplay[] = []; const newTabs: CoreMainMenuHandlerToDisplay[] = [];
for (let i = 0; i < handlers.length; i++) { for (let i = 0; i < handlers.length; i++) {
@ -190,13 +191,18 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
this.updateMoreBadge(); this.updateMoreBadge();
const removedTabs = previousTabs.filter(page => !this.tabs.some(tab => tab.page === page)); let removedHandlersPages: string[] = [];
const mainMenuTab = CoreNavigator.getCurrentMainMenuTab(); if (previousHandlers) {
const allHandlers = this.allHandlers;
removedHandlersPages = previousHandlers.map(handler => handler.page)
.filter(page => !allHandlers.some(handler => handler.page === page));
}
const mainMenuTab = CoreNavigator.getCurrentMainMenuTab();
this.loaded = CoreMainMenuDelegate.areHandlersLoaded(); this.loaded = CoreMainMenuDelegate.areHandlersLoaded();
if (this.loaded && (!mainMenuTab || removedTabs.includes(mainMenuTab))) { if (this.loaded && (!mainMenuTab || removedHandlersPages.includes(mainMenuTab))) {
// No tab selected, select the first one. // No tab selected or handler no longer available, select the first one.
await CoreUtils.nextTick(); await CoreUtils.nextTick();
const tabPage = this.tabs[0] ? this.tabs[0].page : this.morePageName; const tabPage = this.tabs[0] ? this.tabs[0].page : this.morePageName;
@ -205,6 +211,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
// Use navigate instead of mainTabs.select to be able to pass page params. // Use navigate instead of mainTabs.select to be able to pass page params.
CoreNavigator.navigateToSitePath(tabPage, { CoreNavigator.navigateToSitePath(tabPage, {
preferCurrentTab: false,
params: { params: {
urlToOpen: this.urlToOpen, urlToOpen: this.urlToOpen,
redirectPath: this.redirectPath, redirectPath: this.redirectPath,