From cf96e7252cdf66230cc03ddec907168e47d1f250 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Fri, 13 Nov 2020 05:51:03 +0100 Subject: [PATCH] feat(frame): add navigatingTo and navigatedTo events (#9025) --- packages/core/ui/frame/frame-common.ts | 13 +++++++++++++ packages/core/ui/frame/index.d.ts | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/core/ui/frame/frame-common.ts b/packages/core/ui/frame/frame-common.ts index af20f2b90..709b5c211 100644 --- a/packages/core/ui/frame/frame-common.ts +++ b/packages/core/ui/frame/frame-common.ts @@ -249,6 +249,12 @@ export class FrameBase extends CustomLayoutView { } newPage.onNavigatedTo(isBack); + this.notify({ + eventName: Page.navigatedToEvent, + object: this, + isBack, + entry, + }); // Reset executing context after NavigatedTo is raised; // we do not want to execute two navigations in parallel in case @@ -417,6 +423,13 @@ export class FrameBase extends CustomLayoutView { } backstackEntry.resolvedPage.onNavigatingTo(backstackEntry.entry.context, isBack, backstackEntry.entry.bindingContext); + this.notify({ + eventName: Page.navigatingToEvent, + object: this, + isBack, + entry: backstackEntry.entry, + fromEntry:this.currentEntry + }); } public get animated(): boolean { diff --git a/packages/core/ui/frame/index.d.ts b/packages/core/ui/frame/index.d.ts index 55ebe53eb..dabdcda93 100644 --- a/packages/core/ui/frame/index.d.ts +++ b/packages/core/ui/frame/index.d.ts @@ -1,11 +1,17 @@ import { NavigationType, FrameBase } from './frame-common'; -import { Page } from '../page'; +import { NavigatedData, Page } from '../page'; import { Observable, EventData } from '../../data/observable'; import { View } from '../core/view'; import { Transition } from '../transition'; export * from './frame-interfaces'; +export interface NavigationData extends EventData { + entry?: NavigationEntry; + fromEntry?: NavigationEntry; + isBack?: boolean; +} + /** * Represents the logical View unit that is responsible for navigation within an application. * Nested frames are supported, enabling hierarchical navigation scenarios. @@ -210,6 +216,16 @@ export class Frame extends FrameBase { * @param thisArg - An optional parameter which will be used as `this` context for callback execution. */ on(eventNames: string, callback: (args: EventData) => void, thisArg?: any); + + /** + * Raised when navigation to the page has started. + */ + public on(event: 'navigatingTo', callback: (args: NavigationData) => void, thisArg?: any); + + /** + * Raised when navigation to the page has finished. + */ + public on(event: 'navigatedTo', callback: (args: NavigationData) => void, thisArg?: any); } /**