mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #2467 from NativeScript/page-binding-context
Fix: Set the binding context of a page automatically when navigated to.
This commit is contained in:
@@ -17,13 +17,11 @@ class RemovalTrackingGridLayout extends GridLayout {
|
||||
public removedCols = 0;
|
||||
|
||||
public _onRowRemoved(itemSpec: ItemSpec, index: number) {
|
||||
console.log("_onRowRemoved");
|
||||
this.removedRows++;
|
||||
super._onRowRemoved(itemSpec, index);
|
||||
}
|
||||
|
||||
public _onColumnRemoved(itemSpec: ItemSpec, index: number) {
|
||||
console.log("_onColumnRemoved");
|
||||
this.removedCols++;
|
||||
super._onColumnRemoved(itemSpec, index);
|
||||
}
|
||||
|
||||
@@ -230,6 +230,31 @@ export function test_NavigateTo_WithContext() {
|
||||
TKUnit.assertNull(testPage.navigationContext, "Navigation context should be cleared on navigating back");
|
||||
}
|
||||
|
||||
//https://github.com/NativeScript/NativeScript/issues/731
|
||||
export function test_BindingContext_Becomes_NavigationContext_When_NavigatingTo() {
|
||||
let currentPage = frameModule.topmost().currentPage;
|
||||
let testPage: Page;
|
||||
let bindingContext;
|
||||
let pageFactory = function (): Page {
|
||||
testPage = new Page();
|
||||
testPage.on(pageModule.Page.navigatingToEvent, function (args: NavigatedData) {
|
||||
bindingContext = (<Page>args.object).bindingContext;
|
||||
});
|
||||
return testPage;
|
||||
};
|
||||
let navEntry = {
|
||||
create: pageFactory,
|
||||
context: "This is the navigation context",
|
||||
animated: false
|
||||
};
|
||||
let topFrame = frameModule.topmost();
|
||||
topFrame.navigate(navEntry);
|
||||
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.");
|
||||
}
|
||||
|
||||
export function test_FrameBackStack_WhenNavigatingForwardAndBack() {
|
||||
let testPage: Page;
|
||||
let pageFactory = function () {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"nativescript": {
|
||||
"id": "org.nativescript.tests",
|
||||
"tns-ios": {
|
||||
"version": "2.1.0"
|
||||
"version": "2.1.1"
|
||||
},
|
||||
"tns-android": {
|
||||
"version": "2.1.1"
|
||||
@@ -23,4 +23,4 @@
|
||||
"lazy": "1.0.11",
|
||||
"typescript": "^1.8.10"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import * as fileSystemModule from "file-system";
|
||||
import * as frameModule from "ui/frame";
|
||||
import proxy = require("ui/core/proxy");
|
||||
import keyframeAnimation = require("ui/animation/keyframe-animation");
|
||||
import types = require("utils/types");
|
||||
|
||||
let fs: typeof fileSystemModule;
|
||||
function ensureFS() {
|
||||
@@ -201,6 +202,11 @@ export class Page extends ContentView implements dts.Page {
|
||||
|
||||
public onNavigatingTo(context: any, isBackNavigation: boolean) {
|
||||
this._navigationContext = context;
|
||||
|
||||
//https://github.com/NativeScript/NativeScript/issues/731
|
||||
if (!isBackNavigation && !types.isNullOrUndefined(context)){
|
||||
this.bindingContext = context;
|
||||
}
|
||||
this.notify(this.createNavigatedData(Page.navigatingToEvent, isBackNavigation));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user