Merge pull request #1491 from NativeScript/issue-1021

Resolved Issue #1021: The navigatedTo event is called twice for the f…
This commit is contained in:
Rossen Hristov
2016-02-04 17:31:46 +02:00
2 changed files with 23 additions and 11 deletions

View File

@ -5,20 +5,18 @@ import tests = require("../testRunner");
trace.enable();
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);
let started = false;
let page = new Page();
page.id = "mainPage";
page.on(Page.navigatedToEvent, function () {
if (!started) {
started = true;
setTimeout(function () {
tests.runAll();
}, 10);
}
});
page.on(Page.navigatedToEvent, onNavigatedTo);
function onNavigatedTo(args) {
args.object.off(Page.navigatedToEvent, onNavigatedTo);
setTimeout(function () {
tests.runAll();
}, 10);
}
export function createPage() {
return page;
}
}

View File

@ -356,6 +356,7 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
}
public navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
trace.write(`UINavigationControllerImpl.navigationControllerWillShowViewControllerAnimated(${navigationController}, ${viewController}, ${animated})`, trace.categories.NativeLifecycle);
// In this method we need to layout the new page otherwise page will be shown empty and update after that which is bad UX.
let frame = this._owner.get();
if (!frame) {
@ -381,9 +382,22 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
}
newPage.actionBar.update();
//HACK: https://github.com/NativeScript/NativeScript/issues/1021
viewController["willShowCalled"] = true;
}
public navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
trace.write(`UINavigationControllerImpl.navigationControllerDidShowViewControllerAnimated(${navigationController}, ${viewController}, ${animated})`, trace.categories.NativeLifecycle);
//HACK: https://github.com/NativeScript/NativeScript/issues/1021
if (viewController["willShowCalled"] === undefined) {
return;
}
else {
viewController["willShowCalled"] = undefined;
}
let frame = this._owner.get();
if (!frame) {
return;