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 removedCols = 0;
|
||||||
|
|
||||||
public _onRowRemoved(itemSpec: ItemSpec, index: number) {
|
public _onRowRemoved(itemSpec: ItemSpec, index: number) {
|
||||||
console.log("_onRowRemoved");
|
|
||||||
this.removedRows++;
|
this.removedRows++;
|
||||||
super._onRowRemoved(itemSpec, index);
|
super._onRowRemoved(itemSpec, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onColumnRemoved(itemSpec: ItemSpec, index: number) {
|
public _onColumnRemoved(itemSpec: ItemSpec, index: number) {
|
||||||
console.log("_onColumnRemoved");
|
|
||||||
this.removedCols++;
|
this.removedCols++;
|
||||||
super._onColumnRemoved(itemSpec, index);
|
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");
|
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() {
|
export function test_FrameBackStack_WhenNavigatingForwardAndBack() {
|
||||||
let testPage: Page;
|
let testPage: Page;
|
||||||
let pageFactory = function () {
|
let pageFactory = function () {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"nativescript": {
|
"nativescript": {
|
||||||
"id": "org.nativescript.tests",
|
"id": "org.nativescript.tests",
|
||||||
"tns-ios": {
|
"tns-ios": {
|
||||||
"version": "2.1.0"
|
"version": "2.1.1"
|
||||||
},
|
},
|
||||||
"tns-android": {
|
"tns-android": {
|
||||||
"version": "2.1.1"
|
"version": "2.1.1"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as fileSystemModule from "file-system";
|
|||||||
import * as frameModule from "ui/frame";
|
import * as frameModule from "ui/frame";
|
||||||
import proxy = require("ui/core/proxy");
|
import proxy = require("ui/core/proxy");
|
||||||
import keyframeAnimation = require("ui/animation/keyframe-animation");
|
import keyframeAnimation = require("ui/animation/keyframe-animation");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
let fs: typeof fileSystemModule;
|
let fs: typeof fileSystemModule;
|
||||||
function ensureFS() {
|
function ensureFS() {
|
||||||
@@ -201,6 +202,11 @@ export class Page extends ContentView implements dts.Page {
|
|||||||
|
|
||||||
public onNavigatingTo(context: any, isBackNavigation: boolean) {
|
public onNavigatingTo(context: any, isBackNavigation: boolean) {
|
||||||
this._navigationContext = context;
|
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));
|
this.notify(this.createNavigatedData(Page.navigatingToEvent, isBackNavigation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user