feat:Text add truncateAt
This commit is contained in:
parent
a23aa8df0f
commit
fdff5af3d9
@ -172,6 +172,24 @@ public class TextNode extends ViewNode<TextView> {
|
|||||||
new CustomTagHandler()));
|
new CustomTagHandler()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "truncateAt":
|
||||||
|
if (prop.isNumber()) {
|
||||||
|
switch (prop.asNumber().toInt()) {
|
||||||
|
case 1:
|
||||||
|
view.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
view.setEllipsize(TextUtils.TruncateAt.START);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
view.setEllipsize(null);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
view.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
super.blend(view, name, prop);
|
super.blend(view, name, prop);
|
||||||
break;
|
break;
|
||||||
|
@ -50,6 +50,7 @@ @implementation DoricTextNode
|
|||||||
- (UILabel *)build {
|
- (UILabel *)build {
|
||||||
return [[[DoricTextView alloc] init] also:^(DoricTextView *it) {
|
return [[[DoricTextView alloc] init] also:^(DoricTextView *it) {
|
||||||
it.textAlignment = NSTextAlignmentCenter;
|
it.textAlignment = NSTextAlignmentCenter;
|
||||||
|
[self ensureParagraphStyle];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
|||||||
}
|
}
|
||||||
if (self.paragraphStyle) {
|
if (self.paragraphStyle) {
|
||||||
self.paragraphStyle.alignment = alignment;
|
self.paragraphStyle.alignment = alignment;
|
||||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:view.text];
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:view.text ?: @""];
|
||||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [attributedString length])];
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [attributedString length])];
|
||||||
view.attributedText = attributedString;
|
view.attributedText = attributedString;
|
||||||
} else {
|
} else {
|
||||||
@ -133,6 +134,27 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
|||||||
documentAttributes:nil
|
documentAttributes:nil
|
||||||
error:nil];
|
error:nil];
|
||||||
view.attributedText = attStr;
|
view.attributedText = attStr;
|
||||||
|
} else if ([name isEqualToString:@"truncateAt"]) {
|
||||||
|
[prop also:^(NSNumber *truncateAt) {
|
||||||
|
[[self ensureParagraphStyle] also:^(NSMutableParagraphStyle *it) {
|
||||||
|
switch (truncateAt.integerValue) {
|
||||||
|
case 1:
|
||||||
|
it.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
it.lineBreakMode = NSLineBreakByTruncatingHead;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
it.lineBreakMode = NSLineBreakByClipping;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
it.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
[self reloadParagraphStyle];
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
[super blendView:view forPropName:name propValue:prop];
|
[super blendView:view forPropName:name propValue:prop];
|
||||||
}
|
}
|
||||||
@ -142,6 +164,7 @@ - (NSMutableParagraphStyle *)ensureParagraphStyle {
|
|||||||
if (self.paragraphStyle == nil) {
|
if (self.paragraphStyle == nil) {
|
||||||
self.paragraphStyle = [NSMutableParagraphStyle new];
|
self.paragraphStyle = [NSMutableParagraphStyle new];
|
||||||
self.paragraphStyle.alignment = self.view.textAlignment;
|
self.paragraphStyle.alignment = self.view.textAlignment;
|
||||||
|
self.paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||||
}
|
}
|
||||||
return self.paragraphStyle;
|
return self.paragraphStyle;
|
||||||
}
|
}
|
||||||
|
@ -1647,6 +1647,12 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(k, v); }
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(k, v); }
|
||||||
};
|
};
|
||||||
|
(function (TruncateAt) {
|
||||||
|
TruncateAt[TruncateAt["End"] = 0] = "End";
|
||||||
|
TruncateAt[TruncateAt["Middle"] = 1] = "Middle";
|
||||||
|
TruncateAt[TruncateAt["Start"] = 2] = "Start";
|
||||||
|
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
|
||||||
|
})(exports.TruncateAt || (exports.TruncateAt = {}));
|
||||||
var Text = /** @class */ (function (_super) {
|
var Text = /** @class */ (function (_super) {
|
||||||
__extends$3(Text, _super);
|
__extends$3(Text, _super);
|
||||||
function Text() {
|
function Text() {
|
||||||
@ -1704,6 +1710,10 @@ var Text = /** @class */ (function (_super) {
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", String)
|
__metadata$3("design:type", String)
|
||||||
], Text.prototype, "htmlText", void 0);
|
], Text.prototype, "htmlText", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", Number)
|
||||||
|
], Text.prototype, "truncateAt", void 0);
|
||||||
return Text;
|
return Text;
|
||||||
}(View));
|
}(View));
|
||||||
function text(config) {
|
function text(config) {
|
||||||
|
@ -1218,6 +1218,12 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
|
(function (TruncateAt) {
|
||||||
|
TruncateAt[TruncateAt["End"] = 0] = "End";
|
||||||
|
TruncateAt[TruncateAt["Middle"] = 1] = "Middle";
|
||||||
|
TruncateAt[TruncateAt["Start"] = 2] = "Start";
|
||||||
|
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
|
||||||
|
})(exports.TruncateAt || (exports.TruncateAt = {}));
|
||||||
class Text extends View {
|
class Text extends View {
|
||||||
}
|
}
|
||||||
__decorate$3([
|
__decorate$3([
|
||||||
@ -1272,6 +1278,10 @@ __decorate$3([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", String)
|
__metadata$3("design:type", String)
|
||||||
], Text.prototype, "htmlText", void 0);
|
], Text.prototype, "htmlText", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", Number)
|
||||||
|
], Text.prototype, "truncateAt", void 0);
|
||||||
function text(config) {
|
function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
@ -2677,6 +2677,12 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
|
(function (TruncateAt) {
|
||||||
|
TruncateAt[TruncateAt["End"] = 0] = "End";
|
||||||
|
TruncateAt[TruncateAt["Middle"] = 1] = "Middle";
|
||||||
|
TruncateAt[TruncateAt["Start"] = 2] = "Start";
|
||||||
|
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
|
||||||
|
})(exports.TruncateAt || (exports.TruncateAt = {}));
|
||||||
class Text extends View {
|
class Text extends View {
|
||||||
}
|
}
|
||||||
__decorate$3([
|
__decorate$3([
|
||||||
@ -2731,6 +2737,10 @@ __decorate$3([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", String)
|
__metadata$3("design:type", String)
|
||||||
], Text.prototype, "htmlText", void 0);
|
], Text.prototype, "htmlText", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", Number)
|
||||||
|
], Text.prototype, "truncateAt", void 0);
|
||||||
function text(config) {
|
function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
7
doric-js/index.d.ts
vendored
7
doric-js/index.d.ts
vendored
@ -418,6 +418,12 @@ declare module 'doric/lib/src/widget/text' {
|
|||||||
import { View } from "doric/lib/src/ui/view";
|
import { View } from "doric/lib/src/ui/view";
|
||||||
import { Color } from "doric/lib/src/util/color";
|
import { Color } from "doric/lib/src/util/color";
|
||||||
import { Gravity } from "doric/lib/src/util/gravity";
|
import { Gravity } from "doric/lib/src/util/gravity";
|
||||||
|
export enum TruncateAt {
|
||||||
|
End = 0,
|
||||||
|
Middle = 1,
|
||||||
|
Start = 2,
|
||||||
|
Clip = 3
|
||||||
|
}
|
||||||
export class Text extends View {
|
export class Text extends View {
|
||||||
text?: string;
|
text?: string;
|
||||||
textColor?: Color;
|
textColor?: Color;
|
||||||
@ -432,6 +438,7 @@ declare module 'doric/lib/src/widget/text' {
|
|||||||
strikethrough?: boolean;
|
strikethrough?: boolean;
|
||||||
underline?: boolean;
|
underline?: boolean;
|
||||||
htmlText?: string;
|
htmlText?: string;
|
||||||
|
truncateAt?: TruncateAt;
|
||||||
}
|
}
|
||||||
export function text(config: Partial<Text>): Text;
|
export function text(config: Partial<Text>): Text;
|
||||||
}
|
}
|
||||||
|
7
doric-js/lib/src/widget/text.d.ts
vendored
7
doric-js/lib/src/widget/text.d.ts
vendored
@ -1,6 +1,12 @@
|
|||||||
import { View } from "../ui/view";
|
import { View } from "../ui/view";
|
||||||
import { Color } from "../util/color";
|
import { Color } from "../util/color";
|
||||||
import { Gravity } from "../util/gravity";
|
import { Gravity } from "../util/gravity";
|
||||||
|
export declare enum TruncateAt {
|
||||||
|
End = 0,
|
||||||
|
Middle = 1,
|
||||||
|
Start = 2,
|
||||||
|
Clip = 3
|
||||||
|
}
|
||||||
export declare class Text extends View {
|
export declare class Text extends View {
|
||||||
text?: string;
|
text?: string;
|
||||||
textColor?: Color;
|
textColor?: Color;
|
||||||
@ -15,5 +21,6 @@ export declare class Text extends View {
|
|||||||
strikethrough?: boolean;
|
strikethrough?: boolean;
|
||||||
underline?: boolean;
|
underline?: boolean;
|
||||||
htmlText?: string;
|
htmlText?: string;
|
||||||
|
truncateAt?: TruncateAt;
|
||||||
}
|
}
|
||||||
export declare function text(config: Partial<Text>): Text;
|
export declare function text(config: Partial<Text>): Text;
|
||||||
|
@ -26,6 +26,13 @@ import { View, Property } from "../ui/view";
|
|||||||
import { Color } from "../util/color";
|
import { Color } from "../util/color";
|
||||||
import { Gravity } from "../util/gravity";
|
import { Gravity } from "../util/gravity";
|
||||||
import { layoutConfig } from "../util/layoutconfig";
|
import { layoutConfig } from "../util/layoutconfig";
|
||||||
|
export var TruncateAt;
|
||||||
|
(function (TruncateAt) {
|
||||||
|
TruncateAt[TruncateAt["End"] = 0] = "End";
|
||||||
|
TruncateAt[TruncateAt["Middle"] = 1] = "Middle";
|
||||||
|
TruncateAt[TruncateAt["Start"] = 2] = "Start";
|
||||||
|
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
|
||||||
|
})(TruncateAt || (TruncateAt = {}));
|
||||||
export class Text extends View {
|
export class Text extends View {
|
||||||
}
|
}
|
||||||
__decorate([
|
__decorate([
|
||||||
@ -80,6 +87,10 @@ __decorate([
|
|||||||
Property,
|
Property,
|
||||||
__metadata("design:type", String)
|
__metadata("design:type", String)
|
||||||
], Text.prototype, "htmlText", void 0);
|
], Text.prototype, "htmlText", void 0);
|
||||||
|
__decorate([
|
||||||
|
Property,
|
||||||
|
__metadata("design:type", Number)
|
||||||
|
], Text.prototype, "truncateAt", void 0);
|
||||||
export function text(config) {
|
export function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
@ -18,6 +18,13 @@ import { Color } from "../util/color"
|
|||||||
import { Gravity } from "../util/gravity"
|
import { Gravity } from "../util/gravity"
|
||||||
import { layoutConfig } from "../util/layoutconfig"
|
import { layoutConfig } from "../util/layoutconfig"
|
||||||
|
|
||||||
|
export enum TruncateAt {
|
||||||
|
End = 0,
|
||||||
|
Middle = 1,
|
||||||
|
Start = 2,
|
||||||
|
Clip = 3,
|
||||||
|
}
|
||||||
|
|
||||||
export class Text extends View {
|
export class Text extends View {
|
||||||
@Property
|
@Property
|
||||||
text?: string
|
text?: string
|
||||||
@ -57,6 +64,9 @@ export class Text extends View {
|
|||||||
|
|
||||||
@Property
|
@Property
|
||||||
htmlText?: string
|
htmlText?: string
|
||||||
|
|
||||||
|
@Property
|
||||||
|
truncateAt?: TruncateAt
|
||||||
}
|
}
|
||||||
|
|
||||||
export function text(config: Partial<Text>) {
|
export function text(config: Partial<Text>) {
|
||||||
|
10
doric-web/dist/index.js
vendored
10
doric-web/dist/index.js
vendored
@ -2735,6 +2735,12 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators,
|
|||||||
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
||||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
};
|
};
|
||||||
|
(function (TruncateAt) {
|
||||||
|
TruncateAt[TruncateAt["End"] = 0] = "End";
|
||||||
|
TruncateAt[TruncateAt["Middle"] = 1] = "Middle";
|
||||||
|
TruncateAt[TruncateAt["Start"] = 2] = "Start";
|
||||||
|
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
|
||||||
|
})(exports.TruncateAt || (exports.TruncateAt = {}));
|
||||||
class Text extends View {
|
class Text extends View {
|
||||||
}
|
}
|
||||||
__decorate$3([
|
__decorate$3([
|
||||||
@ -2789,6 +2795,10 @@ __decorate$3([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", String)
|
__metadata$3("design:type", String)
|
||||||
], Text.prototype, "htmlText", void 0);
|
], Text.prototype, "htmlText", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", Number)
|
||||||
|
], Text.prototype, "truncateAt", void 0);
|
||||||
function text(config) {
|
function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
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