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

This commit is contained in:
Hristo Hristov
2017-10-26 11:34:15 +03:00
parent 1ee686d9bc
commit 5bcccd28a8
2 changed files with 21 additions and 4 deletions

View File

@ -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 && (<any>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) {
(<any>frame)._backStack.pop();
if (fireNavigationEvents) {
(<any>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);
}

View File

@ -59,6 +59,8 @@ class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControl
owner._handleTwoNavigationBars(backToMoreWillBeVisible);
}
(<any>tabBarController)._willSelectViewController = viewController;
return true;
}
@ -71,6 +73,8 @@ class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControl
if (owner) {
owner._onViewControllerShown(viewController);
}
(<any>tabBarController)._willSelectViewController = undefined;
}
}