mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Total TextBase refactoring + several bug fixes.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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}".`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user