From 6b7d05420e1ca3c6b3e9f559b05cd0dc0711f5e7 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Thu, 4 Feb 2016 16:02:30 +0200 Subject: [PATCH] Resolved Issue #1021: The navigatedTo event is called twice for the first application page. --- apps/tests/app/mainPage.ts | 20 +++++++++----------- ui/frame/frame.ios.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index f0d76ab97..8060aa485 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -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; -} - +} \ No newline at end of file diff --git a/ui/frame/frame.ios.ts b/ui/frame/frame.ios.ts index ce2a31a94..2ab52a4a7 100644 --- a/ui/frame/frame.ios.ts +++ b/ui/frame/frame.ios.ts @@ -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;