Skip to content

Commit fe66104

Browse files
author
vakrilov
committed
Page events
1 parent 8b4807c commit fe66104

File tree

8 files changed

+88
-34
lines changed

8 files changed

+88
-34
lines changed

apps/perf-tests/controls-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ControlsPage extends pagesModule.Page implements definition.Control
3939
this.content = this._mainLayout;
4040
}
4141

42-
public onNavigatedTo(context: any) {
42+
public onNavigatedTo() {
4343
trace.write("Creating " + this._count + " controls...", trace.categories.Test, trace.messageType.info);
4444
this._infoLabel.text = "Creating " + this._count + " controls...";
4545
var startTime = new Date().getMilliseconds();

apps/tests/testRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function isRunningOnEmulator(): boolean {
2323
}
2424

2525
export var allTests = {};
26+
allTests["APPLICATION"] = require("./application-tests");
2627
allTests["DOCKLAYOUT"] = require("./layouts/dock-layout-tests");
2728
allTests["WRAPLAYOUT"] = require("./layouts/wrap-layout-tests");
2829
allTests["ABSOLUTELAYOUT"] = require("./layouts/absolute-layout-tests");
@@ -31,7 +32,6 @@ allTests["STACKLAYOUT"] = require("./layouts/stack-layout-tests");
3132
allTests["PLATFORM"] = require("./platform-tests");
3233
allTests["STYLE-PROPERTIES"] = require("./ui/style/style-properties-tests");
3334
allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests");
34-
allTests["APPLICATION"] = require("./application-tests");
3535
allTests["FILE SYSTEM"] = require("./file-system-tests");
3636
allTests["HTTP"] = require("./http-tests");
3737
allTests["APPLICATION SETTINGS"] = require("./application-settings-tests");

apps/tests/ui/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ export function buildUIWithWeakRefAndInteract<T extends view.View>(createFunc: (
198198
}
199199
}
200200

201-
export function navigate(pageFactory: () => page.Page) {
201+
export function navigate(pageFactory: () => page.Page, navigationContext?: any) {
202202
var currentPage = frame.topmost().currentPage;
203-
frame.topmost().navigate({ create: pageFactory, animated: false });
203+
frame.topmost().navigate({ create: pageFactory, animated: false, context: navigationContext });
204204
TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
205205
}
206206

apps/tests/ui/page/page-tests-common.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ export function test_PageLoaded_is_called_once() {
153153
var handler = function (data) {
154154
loaded++;
155155
}
156-
156+
157157
var pageFactory = function (): PageModule.Page {
158158
page1 = new PageModule.Page();
159-
addLabelToPage(page1, "Page 1");
159+
addLabelToPage(page1, "Page 1");
160160
return page1;
161161
};
162162

@@ -225,29 +225,36 @@ export var test_NavigateToNewPage = function () {
225225

226226
export var test_PageNavigation_EventSequence = function () {
227227
var testPage: PageModule.Page;
228+
var context = { property: "this is the context" };
228229
var eventSequence = [];
229230
var pageFactory = function () {
230231
testPage = new PageModule.Page();
231232
addLabelToPage(testPage);
232-
testPage.onNavigatingFrom = function () {
233-
eventSequence.push("onNavigatingFrom");
234-
}
235-
236-
testPage.onNavigatedFrom = function () {
237-
eventSequence.push("onNavigatedFrom");
238-
}
239233

240-
testPage.onNavigatingTo = function () {
234+
testPage.on(PageModule.Page.navigatingToEvent, function (data: PageModule.NavigatedData) {
241235
eventSequence.push("onNavigatingTo");
242-
}
236+
TKUnit.assertEqual(data.context, context, "onNavigatingTo: navigationContext");
237+
});
243238

244-
testPage.onNavigatedTo = function () {
239+
testPage.on(PageModule.Page.navigatedToEvent, function (data: PageModule.NavigatedData) {
245240
eventSequence.push("onNavigatedTo");
246-
}
241+
TKUnit.assertEqual(data.context, context, "onNavigatedTo : navigationContext");
242+
});
243+
244+
testPage.on(PageModule.Page.navigatingFromEvent, function (data: PageModule.NavigatedData) {
245+
eventSequence.push("onNavigatingFrom");
246+
TKUnit.assertEqual(data.context, context, "onNavigatingFrom: navigationContext");
247+
});
248+
249+
testPage.on(PageModule.Page.navigatedFromEvent, function (data: PageModule.NavigatedData) {
250+
eventSequence.push("onNavigatedFrom");
251+
TKUnit.assertEqual(data.context, context, "onNavigatedFrom: navigationContext");
252+
});
253+
247254
return testPage;
248255
};
249256

250-
helper.navigate(pageFactory);
257+
helper.navigate(pageFactory, context);
251258
helper.goBack();
252259

253260
var expectedEventSequence = ["onNavigatingTo", "onNavigatedTo", "onNavigatingFrom", "onNavigatedFrom"];
@@ -263,9 +270,9 @@ export var test_NavigateTo_WithContext = function () {
263270
var testPage: PageModule.Page;
264271
var pageFactory = function (): PageModule.Page {
265272
testPage = new PageModule.Page();
266-
testPage.onNavigatedTo = function (context) {
273+
testPage.on(PageModule.Page.navigatedToEvent, function () {
267274
////console.log(JSON.stringify(context));
268-
}
275+
});
269276
return testPage;
270277
};
271278
var navEntry = {
@@ -362,7 +369,7 @@ export var test_cssShouldBeAppliedToAllNestedElements = function () {
362369
};
363370

364371
helper.navigate(pageFactory);
365-
372+
366373
var expectedText = "Some text";
367374
try {
368375
TKUnit.assert(label.style.backgroundColor.hex === "#ff00ff00", "Expected: #ff00ff00, Actual: " + label.style.backgroundColor.hex);

ui/frame/frame.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function onFragmentShown(fragment: PageFragmentBody) {
197197

198198
// notify the page
199199
frame._addView(page);
200-
page.onNavigatedTo(entry.entry.context);
200+
page.onNavigatedTo();
201201
frame._processNavigationQueue(page);
202202
}
203203

ui/frame/frame.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
222222
var newPage = newEntry.resolvedPage;
223223

224224
// notify the page
225-
newPage.onNavigatedTo(newEntry.entry.context);
225+
newPage.onNavigatedTo();
226226
frame._processNavigationQueue(newPage);
227227
}
228228

ui/page/page-common.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export module knownCollections {
1717
}
1818

1919
export class Page extends contentView.ContentView implements dts.Page, view.AddArrayFromBuilder {
20+
public static navigatingToEvent = "navigatingTo";
2021
public static navigatedToEvent = "navigatedTo";
22+
public static navigatingFromEvent = "navigatingFrom";
23+
public static navigatedFromEvent = "navigatedFrom";
2124
public static shownModallyEvent = "shownModally";
2225

2326
private _navigationContext: any;
@@ -96,23 +99,37 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA
9699

97100
public onNavigatingTo(context: any) {
98101
this._navigationContext = context;
102+
103+
this.notify({
104+
eventName: Page.navigatingToEvent,
105+
object: this,
106+
context: this.navigationContext
107+
});
99108
}
100109

101-
public onNavigatedTo(context: any) {
102-
this._navigationContext = context;
110+
public onNavigatedTo() {
103111
this.notify({
104112
eventName: Page.navigatedToEvent,
105113
object: this,
106-
context: context
114+
context: this.navigationContext
107115
});
108116
}
109117

110118
public onNavigatingFrom() {
111-
//
119+
this.notify({
120+
eventName: Page.navigatingFromEvent,
121+
object: this,
122+
context: this.navigationContext
123+
});
112124
}
113125

114126
public onNavigatedFrom(isBackNavigation: boolean) {
115-
// TODO: Should we clear navigation context here or somewhere else
127+
this.notify({
128+
eventName: Page.navigatedFromEvent,
129+
object: this,
130+
context: this.navigationContext
131+
});
132+
116133
this._navigationContext = undefined;
117134
}
118135

ui/page/page.d.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ declare module "ui/page" {
1414
//@endprivate
1515

1616
/**
17-
* Defines the data for the Page.navigatedTo event.
17+
* Defines the data for the page navivation events.
1818
*/
1919
export interface NavigatedData extends observable.EventData {
2020
/**
21-
* The navigation context (optional, may be undefined) passed to the Page.onNavigatedTo method.
21+
* The navigation context (optional, may be undefined) passed to the page navigation evetns method.
2222
*/
2323
context: any;
2424
}
@@ -46,11 +46,31 @@ declare module "ui/page" {
4646
* Represents a logical unit for navigation (inside Frame).
4747
*/
4848
export class Page extends contentView.ContentView implements view.AddArrayFromBuilder {
49+
/**
50+
* String value used when hooking to shownModally event.
51+
*/
52+
public static shownModallyEvent: string;
53+
54+
/**
55+
* String value used when hooking to navigatingTo event.
56+
*/
57+
public static navigatingToEvent: string;
58+
4959
/**
5060
* String value used when hooking to navigatedTo event.
5161
*/
5262
public static navigatedToEvent: string;
5363

64+
/**
65+
* String value used when hooking to navigatingFrom event.
66+
*/
67+
public static navigatingFromEvent: string;
68+
69+
/**
70+
* String value used when hooking to navigatedFrom event.
71+
*/
72+
public static navigatedFromEvent: string;
73+
5474
constructor(options?: Options)
5575

5676
/**
@@ -95,7 +115,7 @@ declare module "ui/page" {
95115
* A method called after navigated to the page.
96116
* @param context - The data passed to the page through the NavigationEntry.context property.
97117
*/
98-
onNavigatedTo(context: any): void;
118+
onNavigatedTo(): void;
99119

100120
/**
101121
* A method called before navigating from the page.
@@ -117,14 +137,24 @@ declare module "ui/page" {
117137
on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any);
118138

119139
/**
120-
* Raised when navigation to the page is finished.
140+
* Raised when navigation to the page has started.
141+
*/
142+
on(event: "navigatingTo", callback: (args: NavigatedData) => void, thisArg?: any);
143+
144+
/**
145+
* Raised when navigation to the page has finished.
121146
*/
122147
on(event: "navigatedTo", callback: (args: NavigatedData) => void, thisArg?: any);
123148

124149
/**
125-
* String value used when hooking to shownModally event.
150+
* Raised when navigation from the page has started.
126151
*/
127-
public static shownModallyEvent: string;
152+
on(event: "navigatingFrom", callback: (args: NavigatedData) => void, thisArg?: any);
153+
154+
/**
155+
* Raised when navigation from the page has finished.
156+
*/
157+
on(event: "navigatedFrom", callback: (args: NavigatedData) => void, thisArg?: any);
128158

129159
/**
130160
* Raised when the page is shown as a modal dialog.

0 commit comments

Comments
 (0)