Skip to content

Commit b35dca7

Browse files
committed
chore: Reverted line-height changes
1 parent c47f9fb commit b35dca7

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

packages/core/platforms/ios/src/UIView+NativeScript.m

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ - (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration
2626
BOOL isTextView = [self isKindOfClass:[UITextView class]];
2727
if (lineHeight > 0) {
2828
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
29+
// Note: Avoid using lineSpacing as it will append the height as extra space
30+
paragraphStyle.minimumLineHeight = lineHeight;
2931
// make sure a possible previously set text alignment setting is not lost when line height is specified
3032
if ([self isKindOfClass:[UIButton class]]) {
3133
paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment;
32-
33-
if (((UIButton*)self).titleLabel.font) {
34-
paragraphStyle.lineSpacing = lineHeight - ((UIButton*)self).titleLabel.font.lineHeight;
35-
}
3634
} else {
3735
paragraphStyle.alignment = ((UILabel*)self).textAlignment;
38-
39-
if (((UILabel*)self).font) {
40-
paragraphStyle.lineSpacing = lineHeight - ((UILabel*)self).font.lineHeight;
41-
}
4236
}
4337

4438
if ([self isKindOfClass:[UILabel class]]) {
@@ -95,20 +89,14 @@ -(void)nativeScriptSetFormattedTextDecorationAndTransform:(NSDictionary*)details
9589
BOOL isLabel = [self isKindOfClass:[UILabel class]];
9690
if (lineHeight > 0) {
9791
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
92+
// Note: Avoid using lineSpacing as it will append the height as extra space
93+
paragraphStyle.minimumLineHeight = lineHeight;
9894
// make sure a possible previously set text alignment setting is not lost when line height is specified
9995
if ([self isKindOfClass:[UIButton class]]) {
10096
paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment;
101-
102-
if (((UIButton*)self).titleLabel.font) {
103-
paragraphStyle.lineSpacing = lineHeight - ((UIButton*)self).titleLabel.font.lineHeight;
104-
}
10597
} else {
10698
// Paragraph alignment is also important for tappable spans as NSTextContainer takes it into account
10799
paragraphStyle.alignment = ((UILabel*)self).textAlignment;
108-
109-
if (((UILabel*)self).font) {
110-
paragraphStyle.lineSpacing = lineHeight - ((UILabel*)self).font.lineHeight;
111-
}
112100
}
113101

114102
if (isLabel) {

packages/core/ui/text-base/index.android.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,6 @@ export class TextBase extends TextBaseCommon {
367367
if (!this.formattedText) {
368368
this.nativeTextViewProtected.setTextSize(value);
369369

370-
// Re-calculate line-height
371-
if (this.lineHeight != 0) {
372-
// It's done automatically for API 28+
373-
if (SDK_VERSION < 28) {
374-
this._setLineHeightLegacy(this.lineHeight);
375-
}
376-
}
377-
378370
// Re-calculate letter-spacing
379371
if (this.letterSpacing != 0) {
380372
this._updateLetterSpacing(this.letterSpacing);
@@ -386,12 +378,16 @@ export class TextBase extends TextBaseCommon {
386378
return this.nativeTextViewProtected.getLineHeight() / layout.getDisplayDensity();
387379
}
388380
[lineHeightProperty.setNative](value: number) {
389-
// Note: android throws exception in the case of negative line height
390-
// so make sure that minimum is zero
381+
const dpValue = value * layout.getDisplayDensity();
382+
391383
if (SDK_VERSION >= 28) {
392-
this.nativeTextViewProtected.setLineHeight(Math.max(value * layout.getDisplayDensity(), 0));
384+
this.nativeTextViewProtected.setLineHeight(dpValue);
393385
} else {
394-
this._setLineHeightLegacy(value);
386+
const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
387+
// Actual line spacing is the diff of line height and font height
388+
const lineSpacing = Math.max(dpValue - fontHeight, 0);
389+
390+
this.nativeTextViewProtected.setLineSpacing(lineSpacing, 1);
395391
}
396392
}
397393

@@ -500,15 +496,6 @@ export class TextBase extends TextBaseCommon {
500496
}
501497
}
502498

503-
_setLineHeightLegacy(value: number): void {
504-
const dpValue = value * layout.getDisplayDensity();
505-
const fontHeight = this.nativeTextViewProtected.getPaint().getFontMetricsInt(null);
506-
// Actual line spacing is the diff of line height and font height
507-
const lineSpacing = Math.max(dpValue - fontHeight, 0);
508-
509-
this.nativeTextViewProtected.setLineSpacing(lineSpacing, 1);
510-
}
511-
512499
_updateLetterSpacing(value: number): void {
513500
const emValue = value / this.fontSize;
514501
org.nativescript.widgets.ViewHelper.setLetterspacing(this.nativeTextViewProtected, emValue);

0 commit comments

Comments
 (0)