Text add strikethrough and underline
This commit is contained in:
parent
8faf0e5d33
commit
8cb135b7b1
@ -143,6 +143,16 @@ public class TextNode extends ViewNode<TextView> {
|
||||
}
|
||||
view.setLineSpacing(DoricUtils.dp2px(prop.asNumber().toFloat()), 1);
|
||||
break;
|
||||
case "strikethrough":
|
||||
if (prop.isBoolean()) {
|
||||
view.getPaint().setStrikeThruText(prop.asBoolean().value());
|
||||
}
|
||||
break;
|
||||
case "underline":
|
||||
if (prop.isBoolean()) {
|
||||
view.getPaint().setUnderlineText(prop.asBoolean().value());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
|
@ -46,6 +46,36 @@ class LayoutDemo extends Panel {
|
||||
},
|
||||
height: 50,
|
||||
}),
|
||||
image({
|
||||
imageBase64: icon_refresh,
|
||||
scaleType: ScaleType.ScaleAspectFit,
|
||||
backgroundColor: Color.GRAY,
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.JUST,
|
||||
},
|
||||
height: 50,
|
||||
}),
|
||||
image({
|
||||
imageBase64: icon_refresh,
|
||||
scaleType: ScaleType.ScaleAspectFit,
|
||||
backgroundColor: Color.GRAY,
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.JUST,
|
||||
},
|
||||
height: 50,
|
||||
}),
|
||||
image({
|
||||
imageBase64: icon_refresh,
|
||||
scaleType: ScaleType.ScaleAspectFit,
|
||||
backgroundColor: Color.GRAY,
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.JUST,
|
||||
},
|
||||
height: 50,
|
||||
}),
|
||||
image({
|
||||
imageBase64: icon_refresh,
|
||||
scaleType: ScaleType.ScaleAspectFit,
|
||||
@ -75,9 +105,10 @@ class LayoutDemo extends Panel {
|
||||
flexConfig: {
|
||||
flexDirection: FlexDirection.ROW,
|
||||
width: 200,
|
||||
height: 100,
|
||||
height: 200,
|
||||
flexWrap: Wrap.WRAP,
|
||||
alignContent: Align.CENTER,
|
||||
alignContent: Align.FLEX_END,
|
||||
alignItems: Align.FLEX_START,
|
||||
},
|
||||
backgroundColor: Color.GRAY.alpha(0.1),
|
||||
}
|
||||
|
@ -69,6 +69,18 @@ class TextDemo extends Panel {
|
||||
(this as Text).textColor = Color.BLACK;
|
||||
}
|
||||
}),
|
||||
text({
|
||||
text: "This is strikethrough text.",
|
||||
textSize: 20,
|
||||
textColor: Color.RED,
|
||||
strikethrough: true,
|
||||
}),
|
||||
text({
|
||||
text: "This is underline text.",
|
||||
textSize: 20,
|
||||
textColor: Color.BLUE,
|
||||
underline: true,
|
||||
}),
|
||||
],
|
||||
{
|
||||
space: 10,
|
||||
|
@ -42,6 +42,8 @@ - (void)drawTextInRect:(CGRect)rect {
|
||||
|
||||
@interface DoricTextNode ()
|
||||
@property(nonatomic, strong) NSMutableParagraphStyle *paragraphStyle;
|
||||
@property(nonatomic, assign) NSNumber *underline;
|
||||
@property(nonatomic, assign) NSNumber *strikethrough;
|
||||
@end
|
||||
|
||||
@implementation DoricTextNode
|
||||
@ -53,12 +55,9 @@ - (UILabel *)build {
|
||||
|
||||
- (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
if ([name isEqualToString:@"text"]) {
|
||||
if (self.paragraphStyle) {
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:prop];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [attributedString length])];
|
||||
view.attributedText = attributedString;
|
||||
} else {
|
||||
view.text = prop;
|
||||
if (self.paragraphStyle) {
|
||||
[self reloadParagraphStyle];
|
||||
}
|
||||
} else if ([name isEqualToString:@"textSize"]) {
|
||||
UIFont *font = view.font;
|
||||
@ -113,18 +112,46 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
||||
UIFont *font = [UIFont fontWithName:iconfont size:view.font.pointSize];
|
||||
view.font = font;
|
||||
} else if ([name isEqualToString:@"lineSpacing"]) {
|
||||
self.paragraphStyle = [NSMutableParagraphStyle new];
|
||||
[self.paragraphStyle setLineSpacing:[prop floatValue]];
|
||||
[self.paragraphStyle setAlignment:view.textAlignment];
|
||||
NSString *labelText = view.text ?: @"";
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [labelText length])];
|
||||
view.attributedText = attributedString;
|
||||
[[self ensureParagraphStyle] also:^(NSMutableParagraphStyle *it) {
|
||||
[it setLineSpacing:[prop floatValue]];
|
||||
[self reloadParagraphStyle];
|
||||
}];
|
||||
} else if ([name isEqualToString:@"underline"]) {
|
||||
[[self ensureParagraphStyle] also:^(NSMutableParagraphStyle *it) {
|
||||
self.underline = prop;
|
||||
[self reloadParagraphStyle];
|
||||
}];
|
||||
} else if ([name isEqualToString:@"strikethrough"]) {
|
||||
[[self ensureParagraphStyle] also:^(NSMutableParagraphStyle *it) {
|
||||
self.strikethrough = prop;
|
||||
[self reloadParagraphStyle];
|
||||
}];
|
||||
} else {
|
||||
[super blendView:view forPropName:name propValue:prop];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSMutableParagraphStyle *)ensureParagraphStyle {
|
||||
if (self.paragraphStyle == nil) {
|
||||
self.paragraphStyle = [NSMutableParagraphStyle new];
|
||||
self.paragraphStyle.alignment = self.view.textAlignment;
|
||||
}
|
||||
return self.paragraphStyle;
|
||||
}
|
||||
|
||||
- (void)reloadParagraphStyle {
|
||||
NSString *labelText = self.view.text ?: @"";
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [labelText length])];
|
||||
if (self.underline) {
|
||||
[attributedString addAttribute:NSUnderlineStyleAttributeName value:self.underline range:NSMakeRange(0, [labelText length])];
|
||||
}
|
||||
if (self.strikethrough) {
|
||||
[attributedString addAttribute:NSStrikethroughStyleAttributeName value:self.strikethrough range:NSMakeRange(0, [labelText length])];
|
||||
}
|
||||
self.view.attributedText = attributedString;
|
||||
}
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
[self.view.superview setNeedsLayout];
|
||||
|
@ -1682,6 +1682,14 @@ var Text = /** @class */ (function (_super) {
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "lineSpacing", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "strikethrough", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "underline", void 0);
|
||||
return Text;
|
||||
}(View));
|
||||
function text(config) {
|
||||
|
@ -1250,6 +1250,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "lineSpacing", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "strikethrough", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "underline", void 0);
|
||||
function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
@ -2709,6 +2709,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "lineSpacing", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "strikethrough", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "underline", void 0);
|
||||
function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
4
doric-js/index.d.ts
vendored
4
doric-js/index.d.ts
vendored
@ -484,6 +484,8 @@ declare module 'doric/lib/src/widget/text' {
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
lineSpacing?: number;
|
||||
strikethrough?: boolean;
|
||||
underline?: boolean;
|
||||
}
|
||||
export class Text extends View implements IText {
|
||||
text?: string;
|
||||
@ -496,6 +498,8 @@ declare module 'doric/lib/src/widget/text' {
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
lineSpacing?: number;
|
||||
strikethrough?: boolean;
|
||||
underline?: boolean;
|
||||
}
|
||||
export function text(config: IText): Text;
|
||||
}
|
||||
|
4
doric-js/lib/src/widget/text.d.ts
vendored
4
doric-js/lib/src/widget/text.d.ts
vendored
@ -12,6 +12,8 @@ export interface IText extends IView {
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
lineSpacing?: number;
|
||||
strikethrough?: boolean;
|
||||
underline?: boolean;
|
||||
}
|
||||
export declare class Text extends View implements IText {
|
||||
text?: string;
|
||||
@ -24,5 +26,7 @@ export declare class Text extends View implements IText {
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
lineSpacing?: number;
|
||||
strikethrough?: boolean;
|
||||
underline?: boolean;
|
||||
}
|
||||
export declare function text(config: IText): Text;
|
||||
|
@ -68,6 +68,14 @@ __decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], Text.prototype, "lineSpacing", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], Text.prototype, "strikethrough", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], Text.prototype, "underline", void 0);
|
||||
export function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
@ -29,6 +29,8 @@ export interface IText extends IView {
|
||||
maxWidth?: number
|
||||
maxHeight?: number
|
||||
lineSpacing?: number
|
||||
strikethrough?: boolean
|
||||
underline?: boolean
|
||||
}
|
||||
|
||||
export class Text extends View implements IText {
|
||||
@ -61,6 +63,12 @@ export class Text extends View implements IText {
|
||||
|
||||
@Property
|
||||
lineSpacing?: number
|
||||
|
||||
@Property
|
||||
strikethrough?: boolean
|
||||
|
||||
@Property
|
||||
underline?: boolean
|
||||
}
|
||||
|
||||
export function text(config: IText) {
|
||||
|
8
doric-web/dist/index.js
vendored
8
doric-web/dist/index.js
vendored
@ -2767,6 +2767,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "lineSpacing", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "strikethrough", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Boolean)
|
||||
], Text.prototype, "underline", void 0);
|
||||
function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user