Fixed issue when bindingContext is bound more than once.

This commit is contained in:
Nedyalko Nikolov
2015-04-30 13:48:52 +03:00
parent 315959a590
commit 2e4b2eacf2
10 changed files with 136 additions and 46 deletions

View File

@@ -133,6 +133,7 @@ export class View extends proxy.ProxyObject implements definition.View {
public _cssClasses: Array<string> = [];
private _gesturesObserver: gestures.GesturesObserver;
private _updatingInheritedProperties: boolean;
public _options: definition.Options;
@@ -397,24 +398,40 @@ export class View extends proxy.ProxyObject implements definition.View {
public _onPropertyChanged(property: dependencyObservable.Property, oldValue: any, newValue: any) {
super._onPropertyChanged(property, oldValue, newValue);
// Implement Binding inheritance here.
if (this._childrenCount > 0) {
var shouldUpdateInheritableProps = ((property.metadata && property.metadata.inheritable) &&
property.name !== "bindingContext" &&
!(property instanceof styling.Property));
var that = this;
if (shouldUpdateInheritableProps) {
var notifyEachChild = function (child: View) {
child._setValue(property, newValue, dependencyObservable.ValueSource.Inherited);
child._setValue(property, that._getValue(property), dependencyObservable.ValueSource.Inherited);
return true;
};
this._updatingInheritedProperties = true;
this._eachChildView(notifyEachChild);
this._updatingInheritedProperties = false;
}
}
this._checkMetadataOnPropertyChanged(property.metadata);
}
public _isInheritedChange() {
if (this._updatingInheritedProperties) {
return true;
}
var parentView: View;
parentView = <View>(this.parent);
while (parentView) {
if (parentView._updatingInheritedProperties) {
return true;
}
parentView = <View>(parentView.parent);
}
return false;
}
public _checkMetadataOnPropertyChanged(metadata: dependencyObservable.PropertyMetadata) {
if (metadata.affectsLayout) {
this.requestLayout();
@@ -675,21 +692,6 @@ export class View extends proxy.ProxyObject implements definition.View {
return changed;
}
public _onBindingContextChanged(oldValue: any, newValue: any) {
super._onBindingContextChanged(oldValue, newValue);
if (this._childrenCount === 0) {
return;
}
var thatContext = this.bindingContext;
var eachChild = function (child: View): boolean {
child._setValue(bindable.Bindable.bindingContextProperty, thatContext, dependencyObservable.ValueSource.Inherited);
return true;
}
this._eachChildView(eachChild);
}
private _applyStyleFromScope() {
var rootPage = getAncestor(this, "Page");
if (!rootPage || !rootPage.isLoaded) {
@@ -784,7 +786,7 @@ export class View extends proxy.ProxyObject implements definition.View {
private _inheritProperties(parentView: View) {
var that = this;
var inheritablePropertySetCallback = function (property: dependencyObservable.Property) {
if (property instanceof styling.Property || property.name === "bindingContext") {
if (property instanceof styling.Property) {
return true;
}
if (property.metadata && property.metadata.inheritable) {
@@ -827,7 +829,7 @@ export class View extends proxy.ProxyObject implements definition.View {
view._setValue(bindable.Bindable.bindingContextProperty, undefined, dependencyObservable.ValueSource.Inherited);
var inheritablePropertiesSetCallback = function (property: dependencyObservable.Property) {
if (property instanceof styling.Property || property.name === "bindingContext") {
if (property instanceof styling.Property) {
return true;
}
if (property.metadata && property.metadata.inheritable) {
@@ -892,4 +894,4 @@ export class View extends proxy.ProxyObject implements definition.View {
public focus(): boolean {
return undefined;
}
}
}