textTransform, whiteSpace & textAlignment defaultValue is now “initia” (#3948)

removed enum namespaces
add valueConverter to clipToBounds
This commit is contained in:
Hristo Hristov
2017-04-06 09:50:37 +03:00
committed by GitHub
parent 2c74f93a44
commit f350f7191d
31 changed files with 368 additions and 644 deletions

View File

@ -1,5 +1,5 @@
import { Label as LabelDefinition } from ".";
import { TextBase, WhiteSpace } from "../text-base";
import { TextBase, WhiteSpace, whiteSpaceProperty } from "../text-base";
export * from "../text-base";
@ -7,17 +7,14 @@ export class Label extends TextBase implements LabelDefinition {
nativeView: android.widget.TextView;
get textWrap(): boolean {
return this.style.whiteSpace === WhiteSpace.NORMAL;
return this.style.whiteSpace === "normal";
}
set textWrap(value: boolean) {
this.style.whiteSpace = value ? WhiteSpace.NORMAL : WhiteSpace.NO_WRAP;
this.style.whiteSpace = value ? "normal" : "nowrap";
}
public createNativeView() {
const textView = new android.widget.TextView(this._context);
textView.setSingleLine(true);
textView.setEllipsize(android.text.TextUtils.TruncateAt.END);
return textView;
return new android.widget.TextView(this._context);
}
public initNativeView(): void {
@ -26,6 +23,12 @@ export class Label extends TextBase implements LabelDefinition {
textView.setSingleLine(true);
textView.setEllipsize(android.text.TextUtils.TruncateAt.END);
}
[whiteSpaceProperty.setNative](value: WhiteSpace) {
// Label initial value is no-wrap. set in initNativeView
const newValue = value === "initial" ? "nowrap" : value;
super[whiteSpaceProperty.setNative](newValue);
}
}
// Label.prototype.recycleNativeView = true;

View File

@ -18,13 +18,8 @@ enum FixedSize {
BOTH = 3
}
const zeroLength: Length = {
value: 0,
unit: "px"
};
export class Label extends TextBase implements LabelDefinition {
public nativeView: TNSLabel;
nativeView: TNSLabel;
private _fixedSize: FixedSize;
constructor() {
@ -39,14 +34,10 @@ export class Label extends TextBase implements LabelDefinition {
}
get textWrap(): boolean {
return this.style.whiteSpace === WhiteSpace.NORMAL;
return this.style.whiteSpace === "normal";
}
set textWrap(value: boolean) {
this.style.whiteSpace = value ? WhiteSpace.NORMAL : WhiteSpace.NO_WRAP;
}
public onLoaded() {
super.onLoaded();
this.style.whiteSpace = value ? "normal" : "nowrap";
}
_requestLayoutOnTextChanged(): void {
@ -89,22 +80,18 @@ export class Label extends TextBase implements LabelDefinition {
}
}
[whiteSpaceProperty.getDefault](): WhiteSpace {
return WhiteSpace.NO_WRAP;
}
[whiteSpaceProperty.setNative](value: WhiteSpace) {
const nativeView = this.nativeView;
switch (value) {
case WhiteSpace.NORMAL:
case "normal":
nativeView.lineBreakMode = NSLineBreakMode.ByWordWrapping;
nativeView.numberOfLines = 0;
break;
case WhiteSpace.NO_WRAP:
case "nowrap":
case "initial":
nativeView.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
nativeView.numberOfLines = 1;
break;
default:
throw new Error(`Invalid whitespace value: ${value}. Valid values are: "${WhiteSpace.NORMAL}", "${WhiteSpace.NO_WRAP}".`);
}
}
@ -121,12 +108,9 @@ export class Label extends TextBase implements LabelDefinition {
this.nativeView.layer.backgroundColor = value;
}
[borderTopWidthProperty.getDefault](): Length {
return zeroLength;
}
[borderTopWidthProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let border = nativeView.borderThickness;
const nativeView = this.nativeView;
const border = nativeView.borderThickness;
nativeView.borderThickness = {
top: layout.toDeviceIndependentPixels(this.effectiveBorderTopWidth),
right: border.right,
@ -135,12 +119,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[borderRightWidthProperty.getDefault](): Length {
return zeroLength;
}
[borderRightWidthProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let border = nativeView.borderThickness;
const nativeView = this.nativeView;
const border = nativeView.borderThickness;
nativeView.borderThickness = {
top: border.top,
right: layout.toDeviceIndependentPixels(this.effectiveBorderRightWidth),
@ -149,12 +130,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[borderBottomWidthProperty.getDefault](): Length {
return zeroLength;
}
[borderBottomWidthProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let border = nativeView.borderThickness;
const nativeView = this.nativeView;
const border = nativeView.borderThickness;
nativeView.borderThickness = {
top: border.top,
right: border.right,
@ -163,12 +141,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[borderLeftWidthProperty.getDefault](): Length {
return zeroLength;
}
[borderLeftWidthProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let border = nativeView.borderThickness;
const nativeView = this.nativeView;
const border = nativeView.borderThickness;
nativeView.borderThickness = {
top: border.top,
right: border.right,
@ -177,12 +152,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[paddingTopProperty.getDefault](): Length {
return zeroLength;
}
[paddingTopProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let padding = nativeView.padding;
const nativeView = this.nativeView;
const padding = nativeView.padding;
nativeView.padding = {
top: layout.toDeviceIndependentPixels(this.effectivePaddingTop),
right: padding.right,
@ -191,12 +163,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[paddingRightProperty.getDefault](): Length {
return zeroLength;
}
[paddingRightProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let padding = nativeView.padding;
const nativeView = this.nativeView;
const padding = nativeView.padding;
nativeView.padding = {
top: padding.top,
right: layout.toDeviceIndependentPixels(this.effectivePaddingRight),
@ -205,12 +174,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[paddingBottomProperty.getDefault](): Length {
return zeroLength;
}
[paddingBottomProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let padding = nativeView.padding;
const nativeView = this.nativeView;
const padding = nativeView.padding;
nativeView.padding = {
top: padding.top,
right: padding.right,
@ -219,12 +185,9 @@ export class Label extends TextBase implements LabelDefinition {
};
}
[paddingLeftProperty.getDefault](): Length {
return zeroLength;
}
[paddingLeftProperty.setNative](value: Length) {
let nativeView = this.nativeView;
let padding = nativeView.padding;
const nativeView = this.nativeView;
const padding = nativeView.padding;
nativeView.padding = {
top: padding.top,
right: padding.right,