Merge pull request #358 from NativeScript/hhristov/native-layouts

Style class batch changes before updating native instance.
This commit is contained in:
Hristo Hristov
2015-06-25 17:26:50 +03:00
3 changed files with 22 additions and 0 deletions

View File

@ -123,6 +123,7 @@ export class StyleScope {
return; return;
} }
view.style._beginUpdate();
var i, var i,
selector: cssSelector.CssSelector, selector: cssSelector.CssSelector,
matchedStateSelectors = new Array<cssSelector.CssVisualStateSelector>() matchedStateSelectors = new Array<cssSelector.CssVisualStateSelector>()
@ -153,6 +154,8 @@ export class StyleScope {
this._createVisualsStatesForSelectors(key, matchedStateSelectors); this._createVisualsStatesForSelectors(key, matchedStateSelectors);
} }
} }
view.style._endUpdate();
} }
public getVisualStates(view: view.View): Object { public getVisualStates(view: view.View): Object {

View File

@ -23,6 +23,8 @@ var noStylingClasses = {};
export class Style extends observable.DependencyObservable implements styling.Style { export class Style extends observable.DependencyObservable implements styling.Style {
private _view: view.View; private _view: view.View;
private _inUpdate = false;
private _nativeSetters = new Map<dependencyObservable.Property, any>();
get color(): color.Color { get color(): color.Color {
return this._getValue(colorProperty); return this._getValue(colorProperty);
@ -211,6 +213,16 @@ export class Style extends observable.DependencyObservable implements styling.St
this._view = parentView; this._view = parentView;
} }
public _beginUpdate() {
this._inUpdate = true;
}
public _endUpdate() {
this._inUpdate = false;
this._nativeSetters.forEach((newValue, property, map) => { this._applyStyleProperty(property, newValue); });
this._nativeSetters.clear();
}
public _resetCssValues() { public _resetCssValues() {
var that = this; var that = this;
this._eachSetProperty(function (property: observable.Property) { this._eachSetProperty(function (property: observable.Property) {
@ -263,6 +275,11 @@ export class Style extends observable.DependencyObservable implements styling.St
} }
private _applyStyleProperty(property: dependencyObservable.Property, newValue: any) { private _applyStyleProperty(property: dependencyObservable.Property, newValue: any) {
if (this._inUpdate) {
this._nativeSetters.set(property, newValue);
return;
}
try { try {
var handler: styling.stylers.StylePropertyChangedHandler = getHandler(property, this._view); var handler: styling.stylers.StylePropertyChangedHandler = getHandler(property, this._view);

View File

@ -149,6 +149,8 @@
opacity: number; opacity: number;
//@private //@private
public _beginUpdate();
public _endUpdate();
public _resetCssValues(): void; public _resetCssValues(): void;
public _syncNativeProperties(): void; public _syncNativeProperties(): void;
public _inheritStyleProperty(property: dependencyObservable.Property): void; public _inheritStyleProperty(property: dependencyObservable.Property): void;