mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix Image source property to have None metadata for android - no need for layout invalidation from JS.
ClipToBounds implementation added back. Optimization in style.ts to set native properties at once. Fix height of CommonLayoutParameters.
This commit is contained in:
@@ -13,6 +13,9 @@ var IMAGE = "Image";
|
||||
var ISLOADING = "isLoading";
|
||||
var STRETCH = "stretch";
|
||||
|
||||
// on Android we explicitly set propertySettings to None because android will invalidate its layout (skip unnecessary native call).
|
||||
var AffectsLayout = global.android ? dependencyObservable.PropertyMetadataSettings.None : dependencyObservable.PropertyMetadataSettings.AffectsLayout;
|
||||
|
||||
function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var image = <Image>data.object;
|
||||
var value = data.newValue;
|
||||
@@ -58,7 +61,7 @@ export class Image extends view.View implements definition.Image {
|
||||
new proxy.PropertyMetadata(false, dependencyObservable.PropertyMetadataSettings.None));
|
||||
|
||||
public static stretchProperty = new dependencyObservable.Property(STRETCH, IMAGE,
|
||||
new proxy.PropertyMetadata(enums.Stretch.aspectFit, dependencyObservable.PropertyMetadataSettings.AffectsLayout));
|
||||
new proxy.PropertyMetadata(enums.Stretch.aspectFit, AffectsLayout));
|
||||
|
||||
constructor(options?: definition.Options) {
|
||||
super(options);
|
||||
|
||||
@@ -5,7 +5,7 @@ import proxy = require("ui/core/proxy");
|
||||
|
||||
export class LayoutBase extends view.CustomLayoutView implements definition.LayoutBase, view.AddChildFromBuilder {
|
||||
|
||||
public static clipToBoundsProperty = new dependencyObservable.Property("clipToBounds", "LayoutBase",
|
||||
public static clipToBoundsProperty = new dependencyObservable.Property("clipToBounds", "LayoutBase",
|
||||
new proxy.PropertyMetadata(true, dependencyObservable.PropertyMetadataSettings.None, LayoutBase.onClipToBoundsPropertyChanged));
|
||||
|
||||
private _subViews: Array<view.View> = new Array<view.View>();
|
||||
@@ -71,7 +71,7 @@ export class LayoutBase extends view.CustomLayoutView implements definition.Layo
|
||||
|
||||
get padding(): string {
|
||||
return this.style.padding;
|
||||
}
|
||||
}
|
||||
set padding(value: string) {
|
||||
this.style.padding = value;
|
||||
}
|
||||
@@ -105,9 +105,20 @@ export class LayoutBase extends view.CustomLayoutView implements definition.Layo
|
||||
}
|
||||
|
||||
protected onClipToBoundsChanged(oldValue: boolean, newValue: boolean) {
|
||||
//
|
||||
var nativeView = this._nativeView;
|
||||
if (!nativeView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeView instanceof UIView) {
|
||||
nativeView.clipsToBounds = newValue;
|
||||
}
|
||||
|
||||
else if (nativeView instanceof android.view.ViewGroup) {
|
||||
nativeView.setClipChildren(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static onClipToBoundsPropertyChanged(data: dependencyObservable.PropertyChangeData): void {
|
||||
var layout = <LayoutBase>data.object;
|
||||
layout.onClipToBoundsChanged(data.oldValue, data.newValue);
|
||||
|
||||
@@ -32,10 +32,4 @@ export class Layout extends layoutBase.LayoutBase implements definition.Layout {
|
||||
var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
||||
trace.write(this + " :onMeasure: " + utils.layout.getMode(widthMode) + " " + width + ", " + utils.layout.getMode(heightMode) + " " + height, trace.categories.Layout);
|
||||
}
|
||||
|
||||
protected onClipToBoundsChanged(oldValue: boolean, newValue: boolean): void {
|
||||
if (this._nativeView) {
|
||||
this._nativeView.clipsToBounds = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,23 +116,35 @@ function onPaddingValueChanged(data: observable.PropertyChangeData) {
|
||||
function onPaddingChanged(data: observable.PropertyChangeData) {
|
||||
var thickness = parseThickness(data.newValue);
|
||||
var style = <Style>data.object;
|
||||
|
||||
var valueSource = style._getValueSource(paddingProperty);
|
||||
style._setValue(paddingTopProperty, thickness.top, valueSource);
|
||||
style._setValue(paddingRightProperty, thickness.right, valueSource);
|
||||
style._setValue(paddingBottomProperty, thickness.bottom, valueSource);
|
||||
style._setValue(paddingLeftProperty, thickness.left, valueSource);
|
||||
|
||||
try {
|
||||
style._beginUpdate();
|
||||
style._setValue(paddingTopProperty, thickness.top, valueSource);
|
||||
style._setValue(paddingRightProperty, thickness.right, valueSource);
|
||||
style._setValue(paddingBottomProperty, thickness.bottom, valueSource);
|
||||
style._setValue(paddingLeftProperty, thickness.left, valueSource);
|
||||
}
|
||||
finally {
|
||||
style._endUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
function onMarginChanged(data: observable.PropertyChangeData) {
|
||||
var thickness = parseThickness(data.newValue);
|
||||
var style = <Style>data.object;
|
||||
|
||||
var valueSource = style._getValueSource(marginProperty);
|
||||
style._setValue(marginTopProperty, thickness.top, valueSource);
|
||||
style._setValue(marginRightProperty, thickness.right, valueSource);
|
||||
style._setValue(marginBottomProperty, thickness.bottom, valueSource);
|
||||
style._setValue(marginLeftProperty, thickness.left, valueSource);
|
||||
|
||||
try {
|
||||
style._beginUpdate();
|
||||
style._setValue(marginTopProperty, thickness.top, valueSource);
|
||||
style._setValue(marginRightProperty, thickness.right, valueSource);
|
||||
style._setValue(marginBottomProperty, thickness.bottom, valueSource);
|
||||
style._setValue(marginLeftProperty, thickness.left, valueSource);
|
||||
}
|
||||
finally {
|
||||
style._endUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
function thicknessComparer(x: Thickness, y: Thickness): boolean {
|
||||
@@ -321,10 +333,16 @@ function onFontChanged(data: observable.PropertyChangeData) {
|
||||
|
||||
var newFont = font.Font.parse(data.newValue);
|
||||
var valueSource = style._getValueSource(fontProperty);
|
||||
style._setValue(fontFamilyProperty, newFont.fontFamily, valueSource);
|
||||
style._setValue(fontStyleProperty, newFont.fontStyle, valueSource);
|
||||
style._setValue(fontWeightProperty, newFont.fontWeight, valueSource);
|
||||
style._setValue(fontSizeProperty, newFont.fontSize, valueSource);
|
||||
try {
|
||||
style._beginUpdate();
|
||||
style._setValue(fontFamilyProperty, newFont.fontFamily, valueSource);
|
||||
style._setValue(fontStyleProperty, newFont.fontStyle, valueSource);
|
||||
style._setValue(fontWeightProperty, newFont.fontWeight, valueSource);
|
||||
style._setValue(fontSizeProperty, newFont.fontSize, valueSource);
|
||||
}
|
||||
finally {
|
||||
style._endUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
export class Style extends observable.DependencyObservable implements styling.Style {
|
||||
|
||||
@@ -126,8 +126,8 @@ export class DefaultStyler implements definition.stylers.Styler {
|
||||
}
|
||||
|
||||
// If height is not specified set it as WRAP_CONTENT
|
||||
if (lp.height < 0) {
|
||||
lp.height = -2;
|
||||
if (height < 0) {
|
||||
height = -2;
|
||||
}
|
||||
|
||||
var gravity = 0;
|
||||
|
||||
Reference in New Issue
Block a user