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

@ -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;

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