Layouts are now implemented natively for Android.

This commit is contained in:
hshristov
2015-07-16 01:22:16 +03:00
parent 422cc37d48
commit 41168d3782
5 changed files with 51 additions and 11 deletions

View File

@ -25,4 +25,4 @@ export function createPage() {
page.content = grid;
page.css = "GridLayout { background-color: pink } image { background-color: green }";
return page;
}
}

View File

@ -7,4 +7,4 @@
export class Layout extends layoutBase.LayoutBase {
//
}
}
}

View File

@ -6,7 +6,6 @@ import proxy = require("ui/core/proxy");
// on Android we explicitly set propertySettings to None because android will invalidate its layout (so we skip unnecessary native call).
var AffectsLayout = global.android ? dependencyObservable.PropertyMetadataSettings.None : dependencyObservable.PropertyMetadataSettings.AffectsLayout;
var defailtItemWidthHeight = global.android ? 0 : Number.NaN;
function isWidthHeightValid(value: any): boolean {
return (value >= 0.0 && value !== Number.POSITIVE_INFINITY);
@ -22,10 +21,10 @@ export class WrapLayout extends layouts.LayoutBase implements definition.WrapLay
new proxy.PropertyMetadata(enums.Orientation.horizontal, AffectsLayout, undefined, isValidOrientation));
public static itemWidthProperty = new dependencyObservable.Property("itemWidth", "WrapLayout",
new proxy.PropertyMetadata(defailtItemWidthHeight, AffectsLayout, undefined, isWidthHeightValid));
new proxy.PropertyMetadata(0, AffectsLayout, undefined, isWidthHeightValid));
public static itemHeightProperty = new dependencyObservable.Property("itemHeight", "WrapLayout",
new proxy.PropertyMetadata(defailtItemWidthHeight, AffectsLayout, undefined, isWidthHeightValid));
new proxy.PropertyMetadata(0, AffectsLayout, undefined, isWidthHeightValid));
get orientation(): string {
return this._getValue(WrapLayout.orientationProperty);

View File

@ -147,6 +147,47 @@ function isMinWidthHeightValid(value: number): boolean {
return !isNaN(value) && value >= 0.0 && isFinite(value);
}
function onBackgroundImagePropertyChanged(data: observable.PropertyChangeData) {
var style = <Style>data.object;
var url: string = data.newValue;
var currentBackground = <background.Background>style._getValue(backgroundInternalProperty);
var isValid = false;
if (types.isString(data.newValue)) {
var pattern: RegExp = /url\(('|")(.*?)\1\)/;
var match = url.match(pattern);
if (match && match[2]) {
url = match[2];
}
if (utils.isDataURI(url)) {
var base64Data = url.split(",")[1];
if (types.isDefined(base64Data)) {
style._setValue(backgroundInternalProperty, currentBackground.withImage(imageSource.fromBase64(base64Data)));
isValid = true;
}
}
else if (utils.isFileOrResourcePath(url)) {
style._setValue(backgroundInternalProperty, currentBackground.withImage(imageSource.fromFileOrResource(url)));
isValid = true;
}
else if (url.indexOf("http") !== -1) {
style["_url"] = url;
style._setValue(backgroundInternalProperty, currentBackground.withImage(undefined));
imageSource.fromUrl(url).then((r) => {
if (style && style["_url"] === url) {
style._setValue(backgroundInternalProperty, currentBackground.withImage(r));
}
});
isValid = true;
}
}
if (!isValid) {
style._setValue(backgroundInternalProperty, currentBackground.withImage(undefined));
}
}
function getHandlerInternal(propertyId: number, classInfo: types.ClassInfo): styling.stylers.StylePropertyChangedHandler {
var className = classInfo ? classInfo.name : "default";
var handlerKey = className + propertyId;
@ -439,7 +480,7 @@ export class Style extends observable.DependencyObservable implements styling.St
super();
this._view = parentView;
}
public _beginUpdate() {
this._updateCounter++;
}
@ -450,9 +491,9 @@ export class Style extends observable.DependencyObservable implements styling.St
throw new Error("style._endUpdate() called, but no update is in progress.");
}
if (this._updateCounter === 0) {
this._nativeSetters.forEach((newValue, property, map) => { this._applyStyleProperty(property, newValue); });
this._nativeSetters.clear();
}
this._nativeSetters.forEach((newValue, property, map) => { this._applyStyleProperty(property, newValue); });
this._nativeSetters.clear();
}
}
public _resetCssValues() {

View File

@ -50,7 +50,7 @@ function onBackgroundOrBorderPropertyChanged(v: view.View) {
v.android.setBackgroundDrawable(_defaultBackgrounds.get(viewClass));
}
}
}
}
export class DefaultStyler implements definition.stylers.Styler {
//Background and borders methods
@ -250,7 +250,7 @@ export class TextViewStyler implements definition.stylers.Styler {
if (fontValue.fontSize) {
tv.setTextSize(fontValue.fontSize);
}
}
else {
tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
}