feat:add maxWidth and maxHeight for text
This commit is contained in:
parent
7f16aa23ae
commit
fe33a18213
@ -16,6 +16,7 @@
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.TextView;
|
||||
@ -24,6 +25,7 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
/**
|
||||
* @Description: widget
|
||||
@ -41,6 +43,7 @@ public class TextNode extends ViewNode<TextView> {
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setGravity(Gravity.CENTER);
|
||||
tv.setMaxLines(1);
|
||||
tv.setEllipsize(TextUtils.TruncateAt.END);
|
||||
return tv;
|
||||
}
|
||||
|
||||
@ -87,6 +90,12 @@ public class TextNode extends ViewNode<TextView> {
|
||||
view.setTypeface(iconFont);
|
||||
}
|
||||
|
||||
break;
|
||||
case "maxWidth":
|
||||
view.setMaxWidth(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
break;
|
||||
case "maxHeight":
|
||||
view.setMaxHeight(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
|
@ -26,13 +26,27 @@
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricTextView : UILabel
|
||||
|
||||
@property(nonatomic, assign) CGFloat maxWidth;
|
||||
@property(nonatomic, assign) CGFloat maxHeight;
|
||||
@end
|
||||
|
||||
@implementation DoricTextView
|
||||
- (void)drawTextInRect:(CGRect)rect {
|
||||
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.padding)];
|
||||
}
|
||||
|
||||
- (CGSize)measureSize:(CGSize)targetSize {
|
||||
CGSize measuredSize = [super measureSize:targetSize];
|
||||
CGFloat measuredWidth = measuredSize.width;
|
||||
CGFloat measuredHeight = measuredSize.height;
|
||||
if (self.maxWidth > 0) {
|
||||
measuredWidth = MIN(self.maxWidth, measuredSize.width);
|
||||
}
|
||||
if (self.maxHeight > 0) {
|
||||
measuredHeight = MIN(self.maxHeight, measuredSize.height);
|
||||
}
|
||||
return CGSizeMake(measuredWidth, measuredHeight);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation DoricTextNode
|
||||
@ -82,6 +96,14 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
||||
font = [UIFont fontWithDescriptor:fontDescriptor size:0];
|
||||
}
|
||||
view.font = font;
|
||||
} else if ([name isEqualToString:@"maxWidth"]) {
|
||||
if ([view isKindOfClass:DoricTextView.class]) {
|
||||
((DoricTextView *) view).maxWidth = [prop floatValue];
|
||||
}
|
||||
} else if ([name isEqualToString:@"maxHeight"]) {
|
||||
if ([view isKindOfClass:DoricTextView.class]) {
|
||||
((DoricTextView *) view).maxHeight = [prop floatValue];
|
||||
}
|
||||
} else if ([name isEqualToString:@"font"]) {
|
||||
NSString *iconfont = prop;
|
||||
UIFont *font = [UIFont fontWithName:iconfont size:view.font.pointSize];
|
||||
|
@ -1620,6 +1620,14 @@ var Text = /** @class */ (function (_super) {
|
||||
Property,
|
||||
__metadata$3("design:type", String)
|
||||
], Text.prototype, "font", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxWidth", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxHeight", void 0);
|
||||
return Text;
|
||||
}(View));
|
||||
function text(config) {
|
||||
|
@ -1204,6 +1204,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", String)
|
||||
], Text.prototype, "font", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxWidth", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxHeight", void 0);
|
||||
function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
@ -2663,6 +2663,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", String)
|
||||
], Text.prototype, "font", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxWidth", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxHeight", 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
@ -472,6 +472,8 @@ declare module 'doric/lib/src/widget/text' {
|
||||
textAlignment?: Gravity;
|
||||
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||
font?: string;
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
}
|
||||
export class Text extends View implements IText {
|
||||
text?: string;
|
||||
@ -481,6 +483,8 @@ declare module 'doric/lib/src/widget/text' {
|
||||
textAlignment?: Gravity;
|
||||
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||
font?: string;
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
}
|
||||
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
@ -9,6 +9,8 @@ export interface IText extends IView {
|
||||
textAlignment?: Gravity;
|
||||
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||
font?: string;
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
}
|
||||
export declare class Text extends View implements IText {
|
||||
text?: string;
|
||||
@ -18,5 +20,7 @@ export declare class Text extends View implements IText {
|
||||
textAlignment?: Gravity;
|
||||
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||
font?: string;
|
||||
maxWidth?: number;
|
||||
maxHeight?: number;
|
||||
}
|
||||
export declare function text(config: IText): Text;
|
||||
|
@ -56,6 +56,14 @@ __decorate([
|
||||
Property,
|
||||
__metadata("design:type", String)
|
||||
], Text.prototype, "font", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], Text.prototype, "maxWidth", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], Text.prototype, "maxHeight", void 0);
|
||||
export function text(config) {
|
||||
const ret = new Text;
|
||||
ret.layoutConfig = layoutConfig().fit();
|
||||
|
@ -26,6 +26,8 @@ export interface IText extends IView {
|
||||
textAlignment?: Gravity
|
||||
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
|
||||
font?: string
|
||||
maxWidth?: number
|
||||
maxHeight?: number
|
||||
}
|
||||
|
||||
export class Text extends View implements IText {
|
||||
@ -49,6 +51,12 @@ export class Text extends View implements IText {
|
||||
|
||||
@Property
|
||||
font?: string
|
||||
|
||||
@Property
|
||||
maxWidth?: number
|
||||
|
||||
@Property
|
||||
maxHeight?: number
|
||||
}
|
||||
|
||||
export function text(config: IText) {
|
||||
|
8
doric-web/dist/index.js
vendored
8
doric-web/dist/index.js
vendored
@ -2721,6 +2721,14 @@ __decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", String)
|
||||
], Text.prototype, "font", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxWidth", void 0);
|
||||
__decorate$3([
|
||||
Property,
|
||||
__metadata$3("design:type", Number)
|
||||
], Text.prototype, "maxHeight", 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