Skip to content

Commit 8b978c5

Browse files
committed
fix(ios): StaticLayout text alignment fix
1 parent a35f908 commit 8b978c5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/ui-canvas/canvas.ios.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,8 @@ export class StaticLayout {
23032303
nsAttributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, fullRange);
23042304
}
23052305
draw(canvas: Canvas, maxHeight = Number.MAX_VALUE) {
2306-
canvas.startApplyPaint(this.paint);
2306+
const paint = this.paint;
2307+
canvas.startApplyPaint(paint);
23072308
const ctx = canvas.ctx;
23082309
this.createAttributedStringToDraw(canvas);
23092310
// const attributes = this.paint.getDrawTextAttribs();
@@ -2334,14 +2335,24 @@ export class StaticLayout {
23342335
// UIDrawingText.drawAttributedStringXYWidthHeightWithAttributes(this.nsAttributedString, 0, 0, this.width, maxHeight, attributes);
23352336

23362337
UIGraphicsPushContext(ctx);
2337-
2338+
if (paint.align !== Align.LEFT) {
2339+
let offsetx = 0;
2340+
const width = this.getBounds().size.width;
2341+
if (paint.align === Align.RIGHT) {
2342+
offsetx -= width;
2343+
}
2344+
else {
2345+
offsetx -= width / 2;
2346+
}
2347+
CGContextTranslateCTM(ctx, offsetx, 0);
2348+
}
23382349
this.mToDraw.drawWithRectOptionsContext(
23392350
CGRectMake(0, 0, this.width, maxHeight),
23402351
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesFontLeading,
23412352
null
23422353
);
23432354
UIGraphicsPopContext();
2344-
canvas.finishApplyPaint(this.paint);
2355+
canvas.finishApplyPaint(paint);
23452356
}
23462357
getPaint() {
23472358
return this.paint;

0 commit comments

Comments
 (0)