fix(navigation): fix frame.navigate call inside page.navigatedTo handler (#5649)

This commit is contained in:
Manol Donev
2018-04-11 11:25:54 +03:00
committed by GitHub
parent c06d5bae63
commit cf950e1ebb
2 changed files with 44 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import * as TKUnit from "../TKUnit";
import { Page, NavigatedData } from "tns-core-modules/ui/page";
import { EventData, Page, NavigatedData } from "tns-core-modules/ui/page";
import { topmost as topmostFrame, NavigationTransition } from "tns-core-modules/ui/frame";
import { Color } from "tns-core-modules/color";
import * as helper from "../ui/helper";
@ -377,4 +377,41 @@ export function test_NavigationEvents_WithClearHistory() {
export function test_NavigationEvents_WithClearHistory_WithTransition() {
_test_NavigationEvents_WithClearHistory({ name: "fade", duration: 10 });
}
export function test_Navigate_From_Page_Loaded_Handler() {
_test_Navigate_From_Page_Event_Handler(Page.loadedEvent);
}
export function test_Navigate_From_Page_NavigatedTo_Handler() {
_test_Navigate_From_Page_Event_Handler(Page.navigatedToEvent);
}
function _test_Navigate_From_Page_Event_Handler(eventName: string) {
let secondPageNavigatedTo = false;
const firstPageFactory = function (): Page {
const firstPage = new Page();
firstPage.id = "first-page";
firstPage.on(eventName, (args: EventData) => {
const page = <Page>args.object;
const frame = page.frame;
const secondPageFactory = function (): Page {
const secondPage = new Page();
secondPage.id = "second-page";
secondPage.on(Page.navigatedToEvent, () => { secondPageNavigatedTo = true });
return secondPage;
};
frame.navigate(secondPageFactory);
});
return firstPage;
};
helper.navigateWithEntry({ create: firstPageFactory });
TKUnit.waitUntilReady(() => secondPageNavigatedTo);
}

View File

@ -216,8 +216,13 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
}
this._currentEntry = entry;
this._executingEntry = null;
newPage.onNavigatedTo(isBack);
// Reset executing entry after NavigatedTo is raised;
// we do not want to execute two navigations in parallel in case
// additional navigation is triggered from the NavigatedTo handler.
this._executingEntry = null;
}
public _updateBackstack(entry: BackstackEntry, isBack: boolean): void {