Skip to content

Commit 293f5ac

Browse files
committed
chore(ios): first working version of lineBreak
1 parent d476ec6 commit 293f5ac

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/ui-canvas/index.ios.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,6 @@ function lineBreakToLineBreakMode(value: string) {
22612261
export class StaticLayout {
22622262
rect: CGRect;
22632263
nsAttributedString: NSAttributedString;
2264-
lineBreak: string;
22652264
mToDraw: NSMutableAttributedString;
22662265
public constructor(
22672266
private text: any,
@@ -2301,23 +2300,57 @@ export class StaticLayout {
23012300
break;
23022301
}
23032302

2304-
if (this.lineBreak) {
2305-
paragraphStyle.lineBreakMode = lineBreakToLineBreakMode(this.lineBreak);
2303+
if (this.ellipsize) {
2304+
// for now we only support end because we cant get NSLineBreakStrategy.Standard to work with
2305+
// others
2306+
// paragraphStyle.lineBreakMode = lineBreakToLineBreakMode(this.ellipsize);
2307+
paragraphStyle.lineBreakStrategy = NSLineBreakStrategy.Standard;
23062308
}
23072309
const fullRange = { location: 0, length: nsAttributedString.length };
2308-
nsAttributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, fullRange);
23092310
this.mToDraw = nsAttributedString;
23102311
this.nsAttributedString.enumerateAttributesInRangeOptionsUsingBlock(fullRange, 0 as any, (attributes: NSDictionary<string, any>, range: NSRange, p3: any) => {
23112312
nsAttributedString.addAttributesRange(attributes, range);
23122313
});
2314+
nsAttributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, fullRange);
23132315
}
23142316
draw(canvas: Canvas, maxHeight = Number.MAX_VALUE) {
23152317
canvas.startApplyPaint(this.paint);
23162318
const ctx = canvas.ctx;
23172319
this.createAttributedStringToDraw();
2320+
// const attributes = this.paint.getDrawTextAttribs();
2321+
// if (this.align || this.ellipsize) {
2322+
// let paragraphStyle = attributes.objectForKey(NSParagraphStyleAttributeName) as NSMutableParagraphStyle;
2323+
// if (!paragraphStyle) {
2324+
// paragraphStyle = NSMutableParagraphStyle.alloc().init();
2325+
// attributes.setObjectForKey(paragraphStyle, NSParagraphStyleAttributeName);
2326+
// }
2327+
// switch (this.align) {
2328+
// case LayoutAlignment.ALIGN_CENTER:
2329+
// paragraphStyle.alignment = NSTextAlignment.Center;
2330+
// break;
2331+
// case LayoutAlignment.ALIGN_NORMAL:
2332+
// paragraphStyle.alignment = NSTextAlignment.Left;
2333+
// break;
2334+
// case LayoutAlignment.ALIGN_OPPOSITE:
2335+
// paragraphStyle.alignment = NSTextAlignment.Right;
2336+
// break;
2337+
// }
2338+
// if (this.ellipsize) {
2339+
// paragraphStyle.lineBreakMode = lineBreakToLineBreakMode(this.ellipsize);
2340+
// }
2341+
// }
2342+
// console.log('this.nsAttributedString', this.nsAttributedString);
2343+
// console.log('attributes', attributes);
2344+
// UIGraphicsPushContext(ctx);
2345+
// UIDrawingText.drawAttributedStringXYWidthHeightWithAttributes(this.nsAttributedString, 0, 0, this.width, maxHeight, attributes);
23182346

23192347
UIGraphicsPushContext(ctx);
2320-
this.mToDraw.drawWithRectOptionsContext(CGRectMake(0, 0, this.width, maxHeight), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null);
2348+
2349+
this.mToDraw.drawWithRectOptionsContext(
2350+
CGRectMake(0, 0, this.width, maxHeight),
2351+
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesFontLeading,
2352+
null
2353+
);
23212354
UIGraphicsPopContext();
23222355
canvas.finishApplyPaint(this.paint);
23232356
}

0 commit comments

Comments
 (0)