Total TextBase refactoring + several bug fixes.

This commit is contained in:
Rossen Hristov
2016-12-16 14:53:27 +02:00
parent c8e13c23f0
commit 93d4fa5d57
15 changed files with 434 additions and 653 deletions

View File

@@ -1,5 +1,5 @@
import { Button as ButtonDefinition } from "ui/button";
import { TextBase } from "ui/text-base";
import { TextBase, WhiteSpace } from "ui/text-base";
export * from "ui/text-base";
@@ -7,9 +7,9 @@ export abstract class ButtonBase extends TextBase implements ButtonDefinition {
public static tapEvent = "tap";
get textWrap(): boolean {
return this.style.whiteSpace === "normal";
return this.style.whiteSpace === WhiteSpace.NORMAL;
}
set textWrap(value: boolean) {
this.style.whiteSpace = value ? "normal" : "nowrap";
this.style.whiteSpace = value ? WhiteSpace.NORMAL : WhiteSpace.NO_WRAP;
}
}

View File

@@ -1,6 +1,6 @@
import {
ButtonBase, textProperty, formattedTextProperty, TouchGestureEventData, FormattedString, GestureTypes, TouchAction,
PseudoClassHandler
PseudoClassHandler, TextTransform
} from "./button-common";
export * from "./button-common";
@@ -23,7 +23,6 @@ class ClickListener extends java.lang.Object implements android.view.View.OnClic
export class Button extends ButtonBase {
_button: android.widget.Button;
private _isPressed: boolean;
private _transformationMethod;
private _highlightedHandler: (args: TouchGestureEventData) => void;
get android(): android.widget.Button {
@@ -36,22 +35,6 @@ export class Button extends ButtonBase {
this._button.setOnClickListener(new ClickListener(weakRef));
}
public _setFormattedTextPropertyToNative(value: FormattedString) {
let newText = value ? value._formattedText : null;
if (newText) {
if (!this._transformationMethod) {
this._transformationMethod = this.android.getTransformationMethod();
}
this.android.setTransformationMethod(null);
} else {
if (this._transformationMethod && !this.android.getTransformationMethod()) {
this.android.setTransformationMethod(this._transformationMethod);
}
}
this._button.setText(newText);
}
@PseudoClassHandler("normal", "highlighted", "pressed", "active")
_updateHandler(subscribe: boolean) {
if (subscribe) {

View File

@@ -2,7 +2,7 @@
import {
View, ButtonBase, PseudoClassHandler, textProperty, formattedTextProperty, whiteSpaceProperty,
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace
} from "./button-common";
export * from "./button-common";
@@ -42,18 +42,22 @@ export class Button extends ButtonBase {
}
}
get [whiteSpaceProperty.native](): "normal" | "nowrap" {
return "normal";
get [whiteSpaceProperty.native](): WhiteSpace {
return WhiteSpace.NORMAL;
}
set [whiteSpaceProperty.native](value: "normal" | "nowrap") {
set [whiteSpaceProperty.native](value: WhiteSpace) {
let nativeView = this.nativeView.titleLabel;
if (value === "normal") {
nativeView.lineBreakMode = NSLineBreakMode.ByWordWrapping;
nativeView.numberOfLines = 0;
}
else {
nativeView.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
nativeView.numberOfLines = 1;
switch(value){
case WhiteSpace.NORMAL:
nativeView.lineBreakMode = NSLineBreakMode.ByWordWrapping;
nativeView.numberOfLines = 0;
break;
case WhiteSpace.NO_WRAP:
nativeView.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
nativeView.numberOfLines = 1;
break;
default:
throw new Error(`Invalid whitespace value: ${value}. Valid values are: "${WhiteSpace.NORMAL}", "${WhiteSpace.NO_WRAP}".`);
}
}