Skip to content

Commit e4cf173

Browse files
authored
Merge pull request NativeScript#2472 from NativeScript/nav-binding-context
NavigationEntry.bindingContext property
2 parents d398678 + ffec9c3 commit e4cf173

File tree

12 files changed

+112
-22
lines changed

12 files changed

+112
-22
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
.sublime-grunt.cache
66
tscommand*.tmp.txt
77
.tscache
8-
.vscode
98

109
node_modules/
1110
dist/

.vscode/launch.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch on iOS Device",
6+
"type": "nativescript",
7+
"platform": "ios",
8+
"request": "launch",
9+
"appRoot": "${workspaceRoot}/tests",
10+
"sourceMaps": true,
11+
"diagnosticLogging": false,
12+
"emulator": false
13+
},
14+
{
15+
"name": "Attach on iOS Device",
16+
"type": "nativescript",
17+
"platform": "ios",
18+
"request": "attach",
19+
"appRoot": "${workspaceRoot}/tests",
20+
"sourceMaps": true,
21+
"diagnosticLogging": false,
22+
"emulator": false
23+
},
24+
{
25+
"name": "Launch on iOS Emulator",
26+
"type": "nativescript",
27+
"platform": "ios",
28+
"request": "launch",
29+
"appRoot": "${workspaceRoot}/tests",
30+
"sourceMaps": true,
31+
"diagnosticLogging": false,
32+
"emulator": true
33+
},
34+
{
35+
"name": "Attach on iOS Emulator",
36+
"type": "nativescript",
37+
"platform": "ios",
38+
"request": "attach",
39+
"appRoot": "${workspaceRoot}/tests",
40+
"sourceMaps": true,
41+
"diagnosticLogging": false,
42+
"emulator": true
43+
},
44+
{
45+
"name": "Launch on Android Device",
46+
"type": "nativescript",
47+
"platform": "android",
48+
"request": "launch",
49+
"appRoot": "${workspaceRoot}/tests",
50+
"sourceMaps": true,
51+
"diagnosticLogging": false,
52+
"emulator": false
53+
},
54+
{
55+
"name": "Launch on Android Emulator",
56+
"type": "nativescript",
57+
"platform": "android",
58+
"request": "launch",
59+
"appRoot": "${workspaceRoot}/tests",
60+
"sourceMaps": true,
61+
"diagnosticLogging": false,
62+
"emulator": true
63+
},
64+
{
65+
"name": "Attach on Android Device",
66+
"type": "nativescript",
67+
"platform": "android",
68+
"request": "attach",
69+
"appRoot": "${workspaceRoot}/tests",
70+
"sourceMaps": true,
71+
"diagnosticLogging": false,
72+
"emulator": false
73+
},
74+
{
75+
"name": "Attach on Android Emulator",
76+
"type": "nativescript",
77+
"platform": "android",
78+
"request": "attach",
79+
"appRoot": "${workspaceRoot}/tests",
80+
"sourceMaps": true,
81+
"diagnosticLogging": false,
82+
"emulator": true
83+
}
84+
]
85+
}

.vscode/tasks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"command": "tsc",
6+
"isShellCommand": true,
7+
"args": ["-p", "."],
8+
"showOutput": "always",
9+
"problemMatcher": "$tsc"
10+
}

apps/app/cuteness.io/details-page.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/app/cuteness.io/details-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatedTo="pageNavigatedTo">
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
22
<GridLayout rows="*, auto">
33
<ScrollView>
44
<StackLayout>

apps/app/cuteness.io/main-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function listViewItemTap(args: ListViewItemEventData) {
2323
// Navigate to the details page with context set to the data item for specified index
2424
topmostFrame().navigate({
2525
moduleName: "cuteness.io/details-page",
26-
context: appViewModel.redditItems.getItem(args.index)
26+
bindingContext: appViewModel.redditItems.getItem(args.index)
2727
});
2828
}
2929

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function test_NavigateTo_WithContext() {
231231
}
232232

233233
//https://github.com/NativeScript/NativeScript/issues/731
234-
export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo() {
234+
export function test_NavigateTo_WithBindingContext() {
235235
let currentPage = frameModule.topmost().currentPage;
236236
let testPage: Page;
237237
let bindingContext;
@@ -244,15 +244,15 @@ export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo(
244244
};
245245
let navEntry = {
246246
create: pageFactory,
247-
context: "This is the navigation context",
247+
bindingContext: "bindng context",
248248
animated: false
249249
};
250250
let topFrame = frameModule.topmost();
251251
topFrame.navigate(navEntry);
252252
TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage !== currentPage && testPage.isLayoutValid);
253253
helper.goBack();
254254

255-
TKUnit.assertEqual(bindingContext, navEntry.context, "The Page's bindingContext should be set automatically to the navigation context when navigating to.");
255+
TKUnit.assertEqual(bindingContext, navEntry.bindingContext, "The Page's bindingContext should be equal to the NavigationEntry.bindingContext property when navigating to.");
256256
}
257257

258258
export function test_FrameBackStack_WhenNavigatingForwardAndBack() {

tns-core-modules/ui/frame/frame-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export class Frame extends CustomLayoutView implements definition.Frame {
336336
this.currentPage.onNavigatingFrom(isBack);
337337
}
338338

339-
backstackEntry.resolvedPage.onNavigatingTo(backstackEntry.entry.context, isBack);
339+
backstackEntry.resolvedPage.onNavigatingTo(backstackEntry.entry.context, isBack, backstackEntry.entry.bindingContext);
340340
}
341341

342342
public get animated(): boolean {

tns-core-modules/ui/frame/frame.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ declare module "ui/frame" {
162162
*/
163163
context?: any;
164164

165+
/**
166+
* An object to become the binding context of the page navigating to. Optional.
167+
*/
168+
bindingContext?: any;
169+
165170
/**
166171
* True to navigate to the new Page using animated transitions, false otherwise.
167172
*/

tns-core-modules/ui/page/page-common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ export class Page extends ContentView implements dts.Page {
200200
};
201201
}
202202

203-
public onNavigatingTo(context: any, isBackNavigation: boolean) {
203+
public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any) {
204204
this._navigationContext = context;
205205

206206
//https://github.com/NativeScript/NativeScript/issues/731
207-
if (!isBackNavigation && !types.isNullOrUndefined(context)){
208-
this.bindingContext = context;
207+
if (!isBackNavigation && !types.isNullOrUndefined(bindingContext)){
208+
this.bindingContext = bindingContext;
209209
}
210210
this.notify(this.createNavigatedData(Page.navigatingToEvent, isBackNavigation));
211211
}

0 commit comments

Comments
 (0)