GeezerVison is showing github.com — Page events · alvsgithub/NativeScript@fe66104
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/perf-tests/controls-page.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,7 @@ export class ControlsPage extends pagesModule.Page implements definition.Control | 39 | 39 | this.content = this._mainLayout; | 40 | 40 | } | 41 | 41 |
| 42 | | - public onNavigatedTo(context: any) { | | 42 | + public onNavigatedTo() { | 43 | 43 | trace.write("Creating " + this._count + " controls...", trace.categories.Test, trace.messageType.info); | 44 | 44 | this._infoLabel.text = "Creating " + this._count + " controls..."; | 45 | 45 | var startTime = new Date().getMilliseconds(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/tests/testRunner.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,7 @@ function isRunningOnEmulator(): boolean { | 23 | 23 | } | 24 | 24 |
| 25 | 25 | export var allTests = {}; | | 26 | +allTests["APPLICATION"] = require("./application-tests"); | 26 | 27 | allTests["DOCKLAYOUT"] = require("./layouts/dock-layout-tests"); | 27 | 28 | allTests["WRAPLAYOUT"] = require("./layouts/wrap-layout-tests"); | 28 | 29 | allTests["ABSOLUTELAYOUT"] = require("./layouts/absolute-layout-tests"); | @@ -31,7 +32,6 @@ allTests["STACKLAYOUT"] = require("./layouts/stack-layout-tests"); | 31 | 32 | allTests["PLATFORM"] = require("./platform-tests"); | 32 | 33 | allTests["STYLE-PROPERTIES"] = require("./ui/style/style-properties-tests"); | 33 | 34 | allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests"); | 34 | | -allTests["APPLICATION"] = require("./application-tests"); | 35 | 35 | allTests["FILE SYSTEM"] = require("./file-system-tests"); | 36 | 36 | allTests["HTTP"] = require("./http-tests"); | 37 | 37 | allTests["APPLICATION SETTINGS"] = require("./application-settings-tests"); | |
Collapse file Copy file name to clipboardExpand all lines: apps/tests/ui/helper.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -198,9 +198,9 @@ export function buildUIWithWeakRefAndInteract<T extends view.View>(createFunc: ( | 198 | 198 | } | 199 | 199 | } | 200 | 200 |
| 201 | | -export function navigate(pageFactory: () => page.Page) { | | 201 | +export function navigate(pageFactory: () => page.Page, navigationContext?: any) { | 202 | 202 | var currentPage = frame.topmost().currentPage; | 203 | | - frame.topmost().navigate({ create: pageFactory, animated: false }); | | 203 | + frame.topmost().navigate({ create: pageFactory, animated: false, context: navigationContext }); | 204 | 204 | TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; }); | 205 | 205 | } | 206 | 206 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/tests/ui/page/page-tests-common.ts +24-17Lines changed: 24 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -153,10 +153,10 @@ export function test_PageLoaded_is_called_once() { | 153 | 153 | var handler = function (data) { | 154 | 154 | loaded++; | 155 | 155 | } | 156 | | - | | 156 | + | 157 | 157 | var pageFactory = function (): PageModule.Page { | 158 | 158 | page1 = new PageModule.Page(); | 159 | | - addLabelToPage(page1, "Page 1"); | | 159 | + addLabelToPage(page1, "Page 1"); | 160 | 160 | return page1; | 161 | 161 | }; | 162 | 162 |
| @@ -225,29 +225,36 @@ export var test_NavigateToNewPage = function () { | 225 | 225 |
| 226 | 226 | export var test_PageNavigation_EventSequence = function () { | 227 | 227 | var testPage: PageModule.Page; | | 228 | + var context = { property: "this is the context" }; | 228 | 229 | var eventSequence = []; | 229 | 230 | var pageFactory = function () { | 230 | 231 | testPage = new PageModule.Page(); | 231 | 232 | addLabelToPage(testPage); | 232 | | - testPage.onNavigatingFrom = function () { | 233 | | - eventSequence.push("onNavigatingFrom"); | 234 | | - } | 235 | | - | 236 | | - testPage.onNavigatedFrom = function () { | 237 | | - eventSequence.push("onNavigatedFrom"); | 238 | | - } | 239 | 233 |
| 240 | | - testPage.onNavigatingTo = function () { | | 234 | + testPage.on(PageModule.Page.navigatingToEvent, function (data: PageModule.NavigatedData) { | 241 | 235 | eventSequence.push("onNavigatingTo"); | 242 | | - } | | 236 | + TKUnit.assertEqual(data.context, context, "onNavigatingTo: navigationContext"); | | 237 | + }); | 243 | 238 |
| 244 | | - testPage.onNavigatedTo = function () { | | 239 | + testPage.on(PageModule.Page.navigatedToEvent, function (data: PageModule.NavigatedData) { | 245 | 240 | 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 | + | 247 | 254 | return testPage; | 248 | 255 | }; | 249 | 256 |
| 250 | | - helper.navigate(pageFactory); | | 257 | + helper.navigate(pageFactory, context); | 251 | 258 | helper.goBack(); | 252 | 259 |
| 253 | 260 | var expectedEventSequence = ["onNavigatingTo", "onNavigatedTo", "onNavigatingFrom", "onNavigatedFrom"]; | @@ -263,9 +270,9 @@ export var test_NavigateTo_WithContext = function () { | 263 | 270 | var testPage: PageModule.Page; | 264 | 271 | var pageFactory = function (): PageModule.Page { | 265 | 272 | testPage = new PageModule.Page(); | 266 | | - testPage.onNavigatedTo = function (context) { | | 273 | + testPage.on(PageModule.Page.navigatedToEvent, function () { | 267 | 274 | ////console.log(JSON.stringify(context)); | 268 | | - } | | 275 | + }); | 269 | 276 | return testPage; | 270 | 277 | }; | 271 | 278 | var navEntry = { | @@ -362,7 +369,7 @@ export var test_cssShouldBeAppliedToAllNestedElements = function () { | 362 | 369 | }; | 363 | 370 |
| 364 | 371 | helper.navigate(pageFactory); | 365 | | - | | 372 | + | 366 | 373 | var expectedText = "Some text"; | 367 | 374 | try { | 368 | 375 | TKUnit.assert(label.style.backgroundColor.hex === "#ff00ff00", "Expected: #ff00ff00, Actual: " + label.style.backgroundColor.hex); | |
Collapse file Copy file name to clipboardExpand all lines: ui/frame/frame.android.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -197,7 +197,7 @@ function onFragmentShown(fragment: PageFragmentBody) { | 197 | 197 |
| 198 | 198 | // notify the page | 199 | 199 | frame._addView(page); | 200 | | - page.onNavigatedTo(entry.entry.context); | | 200 | + page.onNavigatedTo(); | 201 | 201 | frame._processNavigationQueue(page); | 202 | 202 | } | 203 | 203 |
| |
Collapse file Copy file name to clipboardExpand all lines: ui/frame/frame.ios.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -222,7 +222,7 @@ class UINavigationControllerImpl extends UINavigationController implements UINav | 222 | 222 | var newPage = newEntry.resolvedPage; | 223 | 223 |
| 224 | 224 | // notify the page | 225 | | - newPage.onNavigatedTo(newEntry.entry.context); | | 225 | + newPage.onNavigatedTo(); | 226 | 226 | frame._processNavigationQueue(newPage); | 227 | 227 | } | 228 | 228 |
| |
Collapse file Copy file name to clipboardExpand all lines: ui/page/page-common.ts +22-5Lines changed: 22 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,10 @@ export module knownCollections { | 17 | 17 | } | 18 | 18 |
| 19 | 19 | export class Page extends contentView.ContentView implements dts.Page, view.AddArrayFromBuilder { | | 20 | + public static navigatingToEvent = "navigatingTo"; | 20 | 21 | public static navigatedToEvent = "navigatedTo"; | | 22 | + public static navigatingFromEvent = "navigatingFrom"; | | 23 | + public static navigatedFromEvent = "navigatedFrom"; | 21 | 24 | public static shownModallyEvent = "shownModally"; | 22 | 25 |
| 23 | 26 | private _navigationContext: any; | @@ -96,23 +99,37 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA | 96 | 99 |
| 97 | 100 | public onNavigatingTo(context: any) { | 98 | 101 | this._navigationContext = context; | | 102 | + | | 103 | + this.notify({ | | 104 | + eventName: Page.navigatingToEvent, | | 105 | + object: this, | | 106 | + context: this.navigationContext | | 107 | + }); | 99 | 108 | } | 100 | 109 |
| 101 | | - public onNavigatedTo(context: any) { | 102 | | - this._navigationContext = context; | | 110 | + public onNavigatedTo() { | 103 | 111 | this.notify({ | 104 | 112 | eventName: Page.navigatedToEvent, | 105 | 113 | object: this, | 106 | | - context: context | | 114 | + context: this.navigationContext | 107 | 115 | }); | 108 | 116 | } | 109 | 117 |
| 110 | 118 | public onNavigatingFrom() { | 111 | | - // | | 119 | + this.notify({ | | 120 | + eventName: Page.navigatingFromEvent, | | 121 | + object: this, | | 122 | + context: this.navigationContext | | 123 | + }); | 112 | 124 | } | 113 | 125 |
| 114 | 126 | 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 | + | 116 | 133 | this._navigationContext = undefined; | 117 | 134 | } | 118 | 135 |
| |
Collapse file Copy file name to clipboardExpand all lines: ui/page/page.d.ts +36-6Lines changed: 36 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,11 +14,11 @@ declare module "ui/page" { | 14 | 14 | //@endprivate | 15 | 15 |
| 16 | 16 | /** | 17 | | - * Defines the data for the Page.navigatedTo event. | | 17 | + * Defines the data for the page navivation events. | 18 | 18 | */ | 19 | 19 | export interface NavigatedData extends observable.EventData { | 20 | 20 | /** | 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. | 22 | 22 | */ | 23 | 23 | context: any; | 24 | 24 | } | @@ -46,11 +46,31 @@ declare module "ui/page" { | 46 | 46 | * Represents a logical unit for navigation (inside Frame). | 47 | 47 | */ | 48 | 48 | 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 | + | 49 | 59 | /** | 50 | 60 | * String value used when hooking to navigatedTo event. | 51 | 61 | */ | 52 | 62 | public static navigatedToEvent: string; | 53 | 63 |
| | 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 | + | 54 | 74 | constructor(options?: Options) | 55 | 75 |
| 56 | 76 | /** | @@ -95,7 +115,7 @@ declare module "ui/page" { | 95 | 115 | * A method called after navigated to the page. | 96 | 116 | * @param context - The data passed to the page through the NavigationEntry.context property. | 97 | 117 | */ | 98 | | - onNavigatedTo(context: any): void; | | 118 | + onNavigatedTo(): void; | 99 | 119 |
| 100 | 120 | /** | 101 | 121 | * A method called before navigating from the page. | @@ -117,14 +137,24 @@ declare module "ui/page" { | 117 | 137 | on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any); | 118 | 138 |
| 119 | 139 | /** | 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. | 121 | 146 | */ | 122 | 147 | on(event: "navigatedTo", callback: (args: NavigatedData) => void, thisArg?: any); | 123 | 148 |
| 124 | 149 | /** | 125 | | - * String value used when hooking to shownModally event. | | 150 | + * Raised when navigation from the page has started. | 126 | 151 | */ | 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); | 128 | 158 |
| 129 | 159 | /** | 130 | 160 | * Raised when the page is shown as a modal dialog. | |
|