Skip to content

Commit 237771a

Browse files
committed
fix(ios): textAlignment not working with letterSpacing
1 parent 4c0aa81 commit 237771a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/label.ios.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export class Label extends LabelBase {
410410
}
411411
if (this.nativeViewProtected) {
412412
this.nativeViewProtected.attributedText = this.attributedString;
413-
this._requestLayoutOnTextChanged()
413+
this._requestLayoutOnTextChanged();
414414
}
415415
}
416416
updateHTMLString(fontSize?: number) {
@@ -580,26 +580,31 @@ export class Label extends LabelBase {
580580
`Invalid text decoration value: ${style.textDecoration}. Valid values are: 'none', 'underline', 'line-through', 'underline line-through'.`
581581
);
582582
}
583+
let paragraphStyle;
584+
const createParagraphStyle = () => {
585+
if (!paragraphStyle) {
586+
paragraphStyle = NSMutableParagraphStyle.alloc().init();
587+
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
588+
// make sure a possible previously set text alignment setting is not lost when line height is specified
589+
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
590+
}
591+
};
583592
if (style.letterSpacing !== 0 && this.nativeTextViewProtected.font) {
584593
const kern = style.letterSpacing * this.nativeTextViewProtected.font.pointSize;
585594
dict.set(NSKernAttributeName, kern);
595+
createParagraphStyle();
586596
}
587-
const isTextView = false;
597+
// const isTextView = false;
588598
if (style.lineHeight !== undefined) {
589599
let lineHeight = style.lineHeight;
590600
if (lineHeight === 0) {
591601
lineHeight = 0.00001;
592602
}
593-
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
603+
createParagraphStyle();
594604
paragraphStyle.minimumLineHeight = lineHeight;
595605
paragraphStyle.maximumLineHeight = lineHeight;
596-
// make sure a possible previously set text alignment setting is not lost when line height is specified
597-
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
598-
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
599-
} else if (isTextView) {
600-
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
601-
paragraphStyle.alignment = this.nativeTextViewProtected.textAlignment;
602-
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
606+
// } else if (isTextView) {
607+
// createParagraphStyle();
603608
}
604609
const source = getTransformedText(isNullOrUndefined(this.text) ? '' : `${this.text}`, this.textTransform);
605610
if (dict.size > 0) {

0 commit comments

Comments
 (0)