From 39050861f395e406362b90c669ec6274eed5f704 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Tue, 19 Jul 2016 11:42:56 +0300 Subject: [PATCH] Add NavigationEntry.bindingContext property Resolves Issue #731 --- .gitignore | 1 - .vscode/launch.json | 85 +++++++++++++++++++++++ .vscode/tasks.json | 10 +++ apps/app/cuteness.io/details-page.ts | 10 --- apps/app/cuteness.io/details-page.xml | 2 +- apps/app/cuteness.io/main-page.ts | 2 +- tests/app/ui/page/page-tests-common.ts | 6 +- tns-core-modules/ui/frame/frame-common.ts | 2 +- tns-core-modules/ui/frame/frame.d.ts | 5 ++ tns-core-modules/ui/page/page-common.ts | 6 +- tns-core-modules/ui/page/page.d.ts | 3 +- tns-core-modules/ui/page/page.ios.ts | 2 +- 12 files changed, 112 insertions(+), 22 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json delete mode 100644 apps/app/cuteness.io/details-page.ts diff --git a/.gitignore b/.gitignore index 4210ef719..32a56d53b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ .sublime-grunt.cache tscommand*.tmp.txt .tscache -.vscode node_modules/ dist/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..3155f4945 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,85 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch on iOS Device", + "type": "nativescript", + "platform": "ios", + "request": "launch", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": false + }, + { + "name": "Attach on iOS Device", + "type": "nativescript", + "platform": "ios", + "request": "attach", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": false + }, + { + "name": "Launch on iOS Emulator", + "type": "nativescript", + "platform": "ios", + "request": "launch", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": true + }, + { + "name": "Attach on iOS Emulator", + "type": "nativescript", + "platform": "ios", + "request": "attach", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": true + }, + { + "name": "Launch on Android Device", + "type": "nativescript", + "platform": "android", + "request": "launch", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": false + }, + { + "name": "Launch on Android Emulator", + "type": "nativescript", + "platform": "android", + "request": "launch", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": true + }, + { + "name": "Attach on Android Device", + "type": "nativescript", + "platform": "android", + "request": "attach", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": false + }, + { + "name": "Attach on Android Emulator", + "type": "nativescript", + "platform": "android", + "request": "attach", + "appRoot": "${workspaceRoot}/tests", + "sourceMaps": true, + "diagnosticLogging": false, + "emulator": true + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..3dcb37998 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "tsc", + "isShellCommand": true, + "args": ["-p", "."], + "showOutput": "always", + "problemMatcher": "$tsc" +} \ No newline at end of file diff --git a/apps/app/cuteness.io/details-page.ts b/apps/app/cuteness.io/details-page.ts deleted file mode 100644 index 6f395cc00..000000000 --- a/apps/app/cuteness.io/details-page.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {Page} from "ui/page"; -import {EventData as ObservableEventData} from "data/observable"; - -// Event handler for Page "navigatedTo" event attached in details-page.xml -export function pageNavigatedTo(args: ObservableEventData) { - // Get the event sender - var page = args.object; - - page.bindingContext = page.navigationContext; -} diff --git a/apps/app/cuteness.io/details-page.xml b/apps/app/cuteness.io/details-page.xml index 3157ce42d..7a45ae201 100644 --- a/apps/app/cuteness.io/details-page.xml +++ b/apps/app/cuteness.io/details-page.xml @@ -1,4 +1,4 @@ - + diff --git a/apps/app/cuteness.io/main-page.ts b/apps/app/cuteness.io/main-page.ts index 3c7515209..4e50176ae 100644 --- a/apps/app/cuteness.io/main-page.ts +++ b/apps/app/cuteness.io/main-page.ts @@ -23,7 +23,7 @@ export function listViewItemTap(args: ListViewItemEventData) { // Navigate to the details page with context set to the data item for specified index topmostFrame().navigate({ moduleName: "cuteness.io/details-page", - context: appViewModel.redditItems.getItem(args.index) + bindingContext: appViewModel.redditItems.getItem(args.index) }); } diff --git a/tests/app/ui/page/page-tests-common.ts b/tests/app/ui/page/page-tests-common.ts index 8bc07ebb0..6475eba21 100644 --- a/tests/app/ui/page/page-tests-common.ts +++ b/tests/app/ui/page/page-tests-common.ts @@ -231,7 +231,7 @@ export function test_NavigateTo_WithContext() { } //https://github.com/NativeScript/NativeScript/issues/731 -export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo() { +export function test_NavigateTo_WithBindingContext() { let currentPage = frameModule.topmost().currentPage; let testPage: Page; let bindingContext; @@ -244,7 +244,7 @@ export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo( }; let navEntry = { create: pageFactory, - context: "This is the navigation context", + bindingContext: "bindng context", animated: false }; let topFrame = frameModule.topmost(); @@ -252,7 +252,7 @@ export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo( TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage !== currentPage && testPage.isLayoutValid); helper.goBack(); - TKUnit.assertEqual(bindingContext, navEntry.context, "The Page's bindingContext should be set automatically to the navigation context when navigating to."); + TKUnit.assertEqual(bindingContext, navEntry.bindingContext, "The Page's bindingContext should be equal to the NavigationEntry.bindingContext property when navigating to."); } export function test_FrameBackStack_WhenNavigatingForwardAndBack() { diff --git a/tns-core-modules/ui/frame/frame-common.ts b/tns-core-modules/ui/frame/frame-common.ts index b24984897..ad5e6fc5d 100644 --- a/tns-core-modules/ui/frame/frame-common.ts +++ b/tns-core-modules/ui/frame/frame-common.ts @@ -336,7 +336,7 @@ export class Frame extends CustomLayoutView implements definition.Frame { this.currentPage.onNavigatingFrom(isBack); } - backstackEntry.resolvedPage.onNavigatingTo(backstackEntry.entry.context, isBack); + backstackEntry.resolvedPage.onNavigatingTo(backstackEntry.entry.context, isBack, backstackEntry.entry.bindingContext); } public get animated(): boolean { diff --git a/tns-core-modules/ui/frame/frame.d.ts b/tns-core-modules/ui/frame/frame.d.ts index 430e06452..33dcdb9f8 100644 --- a/tns-core-modules/ui/frame/frame.d.ts +++ b/tns-core-modules/ui/frame/frame.d.ts @@ -162,6 +162,11 @@ declare module "ui/frame" { */ context?: any; + /** + * An object to become the binding context of the page navigating to. Optional. + */ + bindingContext?: any; + /** * True to navigate to the new Page using animated transitions, false otherwise. */ diff --git a/tns-core-modules/ui/page/page-common.ts b/tns-core-modules/ui/page/page-common.ts index e85b228c6..08e891ee6 100644 --- a/tns-core-modules/ui/page/page-common.ts +++ b/tns-core-modules/ui/page/page-common.ts @@ -200,12 +200,12 @@ export class Page extends ContentView implements dts.Page { }; } - public onNavigatingTo(context: any, isBackNavigation: boolean) { + public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext: any) { this._navigationContext = context; //https://github.com/NativeScript/NativeScript/issues/731 - if (!isBackNavigation && !types.isNullOrUndefined(context)){ - this.bindingContext = context; + if (!isBackNavigation && !types.isNullOrUndefined(bindingContext)){ + this.bindingContext = bindingContext; } this.notify(this.createNavigatedData(Page.navigatingToEvent, isBackNavigation)); } diff --git a/tns-core-modules/ui/page/page.d.ts b/tns-core-modules/ui/page/page.d.ts index 4ff7c9cdd..34f9d8e32 100644 --- a/tns-core-modules/ui/page/page.d.ts +++ b/tns-core-modules/ui/page/page.d.ts @@ -227,8 +227,9 @@ declare module "ui/page" { * A method called before navigating to the page. * @param context - The data passed to the page through the NavigationEntry.context property. * @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise. + * @param bindingContext - An object to become the binding context of the page navigating to. */ - onNavigatingTo(context: any, isBackNavigation: boolean): void; + onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext: any): void; /** * A method called after navigated to the page. diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index fed5f9317..ed90002da 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -129,7 +129,7 @@ class UIViewControllerImpl extends UIViewController { // Don't raise event if currentPage was showing modal page. if (!page._presentedViewController && newEntry && (!frame || frame.currentPage !== page)) { let isBack = isBackNavigation(page, newEntry) - page.onNavigatingTo(newEntry.entry.context, isBack); + page.onNavigatingTo(newEntry.entry.context, isBack, newEntry.entry.bindingContext); } if (frame) {