mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Layouts are now implemented natively for Android.
This commit is contained in:
@ -25,4 +25,4 @@ export function createPage() {
|
|||||||
page.content = grid;
|
page.content = grid;
|
||||||
page.css = "GridLayout { background-color: pink } image { background-color: green }";
|
page.css = "GridLayout { background-color: pink } image { background-color: green }";
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
2
ui/layouts/layout.d.ts
vendored
2
ui/layouts/layout.d.ts
vendored
@ -7,4 +7,4 @@
|
|||||||
export class Layout extends layoutBase.LayoutBase {
|
export class Layout extends layoutBase.LayoutBase {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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).
|
// 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 AffectsLayout = global.android ? dependencyObservable.PropertyMetadataSettings.None : dependencyObservable.PropertyMetadataSettings.AffectsLayout;
|
||||||
var defailtItemWidthHeight = global.android ? 0 : Number.NaN;
|
|
||||||
|
|
||||||
function isWidthHeightValid(value: any): boolean {
|
function isWidthHeightValid(value: any): boolean {
|
||||||
return (value >= 0.0 && value !== Number.POSITIVE_INFINITY);
|
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));
|
new proxy.PropertyMetadata(enums.Orientation.horizontal, AffectsLayout, undefined, isValidOrientation));
|
||||||
|
|
||||||
public static itemWidthProperty = new dependencyObservable.Property("itemWidth", "WrapLayout",
|
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",
|
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 {
|
get orientation(): string {
|
||||||
return this._getValue(WrapLayout.orientationProperty);
|
return this._getValue(WrapLayout.orientationProperty);
|
||||||
|
@ -147,6 +147,47 @@ function isMinWidthHeightValid(value: number): boolean {
|
|||||||
return !isNaN(value) && value >= 0.0 && isFinite(value);
|
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 {
|
function getHandlerInternal(propertyId: number, classInfo: types.ClassInfo): styling.stylers.StylePropertyChangedHandler {
|
||||||
var className = classInfo ? classInfo.name : "default";
|
var className = classInfo ? classInfo.name : "default";
|
||||||
var handlerKey = className + propertyId;
|
var handlerKey = className + propertyId;
|
||||||
@ -439,7 +480,7 @@ export class Style extends observable.DependencyObservable implements styling.St
|
|||||||
super();
|
super();
|
||||||
this._view = parentView;
|
this._view = parentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _beginUpdate() {
|
public _beginUpdate() {
|
||||||
this._updateCounter++;
|
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.");
|
throw new Error("style._endUpdate() called, but no update is in progress.");
|
||||||
}
|
}
|
||||||
if (this._updateCounter === 0) {
|
if (this._updateCounter === 0) {
|
||||||
this._nativeSetters.forEach((newValue, property, map) => { this._applyStyleProperty(property, newValue); });
|
this._nativeSetters.forEach((newValue, property, map) => { this._applyStyleProperty(property, newValue); });
|
||||||
this._nativeSetters.clear();
|
this._nativeSetters.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public _resetCssValues() {
|
public _resetCssValues() {
|
||||||
|
@ -50,7 +50,7 @@ function onBackgroundOrBorderPropertyChanged(v: view.View) {
|
|||||||
v.android.setBackgroundDrawable(_defaultBackgrounds.get(viewClass));
|
v.android.setBackgroundDrawable(_defaultBackgrounds.get(viewClass));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DefaultStyler implements definition.stylers.Styler {
|
export class DefaultStyler implements definition.stylers.Styler {
|
||||||
//Background and borders methods
|
//Background and borders methods
|
||||||
@ -250,7 +250,7 @@ export class TextViewStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
if (fontValue.fontSize) {
|
if (fontValue.fontSize) {
|
||||||
tv.setTextSize(fontValue.fontSize);
|
tv.setTextSize(fontValue.fontSize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
|
tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user