From 5bcccd28a80f37c892d20a29400e32d78253add1 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Thu, 26 Oct 2017 11:34:15 +0300 Subject: [PATCH] Fix: when page disappears because parent viewController is removed (e.g. selecting different tab in TabBar) our navigation stack was incorrectly removing backstack entry. This fix may not work if the tab is hosted in Page but it is unlikely that someone will host Page->TabView->Frame->Page --- tns-core-modules/ui/page/page.ios.ts | 21 ++++++++++++++++---- tns-core-modules/ui/tab-view/tab-view.ios.ts | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index c7c2127bf..b22858e9f 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -190,8 +190,13 @@ class UIViewControllerImpl extends UIViewController { } const frame = owner.frame; - // Skip navigation events if we are hiding because we are about to show modal page. + // Skip navigation events if we are hiding because we are about to show modal page + // or because we are in tab and another controller is selected. + const tab = this.tabBarController; if (!owner._presentedViewController && frame && frame.currentPage === owner) { + const willSelectViewController = tab && (tab)._willSelectViewController; + if (!willSelectViewController + || willSelectViewController === tab.selectedViewController) { let isBack = isBackNavigationFrom(this, owner); owner.onNavigatingFrom(isBack); } @@ -225,8 +230,16 @@ class UIViewControllerImpl extends UIViewController { const frame = page.frame; // We are not modal page, have frame with backstack and navigation queue is empty and currentPage is closed // then pop our backstack. + // If we are in frame wich is in tab and tab.selectedControler is not the frame + // skip navigation. + const tab = this.tabBarController; + const fireNavigationEvents = !tab + || tab.selectedViewController === this.navigationController; + if (!modalParent && frame && frame.backStack.length > 0 && frame.navigationQueueIsEmpty() && frame.currentPage === page) { - (frame)._backStack.pop(); + if (fireNavigationEvents) { + (frame)._backStack.pop(); + } } page._enableLoadedEvents = true; @@ -247,7 +260,7 @@ class UIViewControllerImpl extends UIViewController { page._enableLoadedEvents = false; - if (!modalParent) { + if (!modalParent && fireNavigationEvents) { // Last raise onNavigatedFrom event if we are not modally shown. page.onNavigatedFrom(isBack); } @@ -425,7 +438,7 @@ export class Page extends PageBase { if (child === this.actionBar) { return true; } - + // Don't add modal pages our visual tree. if (child !== this.content) { return true; diff --git a/tns-core-modules/ui/tab-view/tab-view.ios.ts b/tns-core-modules/ui/tab-view/tab-view.ios.ts index fb16fe5bc..94808921b 100644 --- a/tns-core-modules/ui/tab-view/tab-view.ios.ts +++ b/tns-core-modules/ui/tab-view/tab-view.ios.ts @@ -59,6 +59,8 @@ class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControl owner._handleTwoNavigationBars(backToMoreWillBeVisible); } + (tabBarController)._willSelectViewController = viewController; + return true; } @@ -71,6 +73,8 @@ class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControl if (owner) { owner._onViewControllerShown(viewController); } + + (tabBarController)._willSelectViewController = undefined; } }