mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
multiple text-decoration values support added
This commit is contained in:
29
apps/ui-tests-app/css/text-decoration.xml
Normal file
29
apps/ui-tests-app/css/text-decoration.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<Page>
|
||||
<ScrollView>
|
||||
<StackLayout>
|
||||
<Label text="Label" style="text-decoration:none" />
|
||||
<Label text="Label" style="text-decoration:underline" />
|
||||
<Label text="Label" style="text-decoration:line-through" />
|
||||
<Label text="Label" style="text-decoration:line-through underline" />
|
||||
<Label text="Label" style="text-decoration:line-through underline none" />
|
||||
|
||||
<TextField text="TextField" style="text-decoration:none" />
|
||||
<TextField text="TextField" style="text-decoration:underline" />
|
||||
<TextField text="TextField" style="text-decoration:line-through" />
|
||||
<TextField text="TextField" style="text-decoration:underline line-through" />
|
||||
<TextField text="TextField" style="text-decoration:underline line-through none" />
|
||||
|
||||
<TextView text="TextView" style="text-decoration:none" />
|
||||
<TextView text="TextView" style="text-decoration:underline" />
|
||||
<TextView text="TextView" style="text-decoration:line-through" />
|
||||
<TextView text="TextView" style="text-decoration:line-through underline" />
|
||||
<TextView text="TextView" style="text-decoration:line-through underline none" />
|
||||
|
||||
<Button text="Button" style="text-decoration:none" />
|
||||
<Button text="Button" style="text-decoration:underline" />
|
||||
<Button text="Button" style="text-decoration:line-through" />
|
||||
<Button text="Button" style="text-decoration:underline line-through" />
|
||||
<Button text="Button" style="text-decoration:underline line-through none" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</Page>
|
@ -23,13 +23,12 @@ export function textAlignConverter(value: string): string {
|
||||
}
|
||||
|
||||
export function textDecorationConverter(value: string): string {
|
||||
switch (value) {
|
||||
case enums.TextDecoration.none:
|
||||
case enums.TextDecoration.underline:
|
||||
case enums.TextDecoration.lineThrough:
|
||||
return value;
|
||||
default:
|
||||
throw new Error("CSS text-decoration \"" + value + "\" is not supported.");
|
||||
var values = (value + "").split(" ");
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.underline) !== -1 || values.indexOf(enums.TextDecoration.lineThrough) !== -1) {
|
||||
return value;
|
||||
} else {
|
||||
throw new Error("CSS text-decoration \"" + value + "\" is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,9 @@ function isVisibilityValid(value: string): boolean {
|
||||
}
|
||||
|
||||
function isTextDecorationValid(value: string): boolean {
|
||||
return value === enums.TextDecoration.none || value === enums.TextDecoration.underline || value === enums.TextDecoration.lineThrough;
|
||||
var values = (value + "").split(" ");
|
||||
|
||||
return values.indexOf(enums.TextDecoration.none) !== -1 || values.indexOf(enums.TextDecoration.underline) !== -1 || values.indexOf(enums.TextDecoration.lineThrough) !== -1;
|
||||
}
|
||||
|
||||
function onVisibilityChanged(data: PropertyChangeData) {
|
||||
|
@ -469,19 +469,23 @@ export class TextViewStyler implements definition.stylers.Styler {
|
||||
}
|
||||
|
||||
function setTextDecoration(view: android.widget.TextView, value: string) {
|
||||
switch (value) {
|
||||
case enums.TextDecoration.none:
|
||||
view.setPaintFlags(view.getPaintFlags());
|
||||
break;
|
||||
case enums.TextDecoration.underline:
|
||||
view.setPaintFlags(view.getPaintFlags() | android.graphics.Paint.UNDERLINE_TEXT_FLAG);
|
||||
break;
|
||||
case enums.TextDecoration.lineThrough:
|
||||
view.setPaintFlags(view.getPaintFlags() | android.graphics.Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
var flags = view.getPaintFlags();
|
||||
|
||||
var values = (value + "").split(" ");
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.underline) !== -1) {
|
||||
flags = flags | android.graphics.Paint.UNDERLINE_TEXT_FLAG;
|
||||
}
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.lineThrough) !== -1) {
|
||||
flags = flags | android.graphics.Paint.STRIKE_THRU_TEXT_FLAG;
|
||||
}
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.none) === -1) {
|
||||
view.setPaintFlags(flags);
|
||||
} else {
|
||||
view.setPaintFlags(0);
|
||||
}
|
||||
}
|
||||
|
||||
export class ActivityIndicatorStyler implements definition.stylers.Styler {
|
||||
|
@ -910,29 +910,32 @@ function setTextAlignment(view: TextUIView, value: string) {
|
||||
}
|
||||
|
||||
function setTextDecoration(view: TextUIView, value: string) {
|
||||
switch (value) {
|
||||
case enums.TextDecoration.none:
|
||||
view.text = view.attributedText ? view.attributedText.string : view.text;
|
||||
break;
|
||||
case enums.TextDecoration.underline:
|
||||
setTextDecorationNative(view, view.text || view.attributedText, NSUnderlineStyleAttributeName);
|
||||
break;
|
||||
case enums.TextDecoration.lineThrough:
|
||||
setTextDecorationNative(view, view.text || view.attributedText, NSStrikethroughStyleAttributeName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
var attributes: NSMutableDictionary = NSMutableDictionary.alloc().init();
|
||||
var values = (value + "").split(" ");
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.underline) !== -1) {
|
||||
attributes.setObjectForKey(NSUnderlineStyle.NSUnderlineStyleSingle, NSUnderlineStyleAttributeName);
|
||||
}
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.lineThrough) !== -1) {
|
||||
attributes.setObjectForKey(NSUnderlineStyle.NSUnderlineStyleSingle, NSStrikethroughStyleAttributeName);
|
||||
}
|
||||
|
||||
if (values.indexOf(enums.TextDecoration.none) === -1) {
|
||||
setTextDecorationNative(view, view.text || view.attributedText, attributes);
|
||||
} else {
|
||||
setTextDecorationNative(view, view.text || view.attributedText, NSMutableDictionary.alloc().init());
|
||||
}
|
||||
}
|
||||
|
||||
function setTextDecorationNative(view: TextUIView, value: string | NSAttributedString, attribute: string) {
|
||||
function setTextDecorationNative(view: TextUIView, value: string | NSAttributedString, attributes: NSMutableDictionary) {
|
||||
var attributedString: NSMutableAttributedString;
|
||||
|
||||
if (value instanceof NSAttributedString) {
|
||||
attributedString = NSMutableAttributedString.alloc().initWithAttributedString(value);
|
||||
attributedString.addAttributesRange(<any>{ [attribute]: NSUnderlineStyle.NSUnderlineStyleSingle }, NSRangeFromString(attributedString.string));
|
||||
attributedString.addAttributesRange(attributes, NSRangeFromString(attributedString.string));
|
||||
} else {
|
||||
view.attributedText = NSAttributedString.alloc().initWithStringAttributes(<string>value, <any>{ [attribute]: NSUnderlineStyle.NSUnderlineStyleSingle });
|
||||
view.attributedText = NSAttributedString.alloc().initWithStringAttributes(<string>value, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user