Skip to content

Commit df4824a

Browse files
committed
chore: Removed letter spacing calculations
1 parent e7ee717 commit df4824a

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ - (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration
1515
}
1616
BOOL isTextType = [self isKindOfClass:[UITextField class]] || [self isKindOfClass:[UITextView class]] | [self isKindOfClass:[UILabel class]] | [self isKindOfClass:[UIButton class]];
1717

18-
if (letterSpacing != 0 && isTextType) {
19-
NSNumber *kern = [NSNumber numberWithDouble:letterSpacing];
18+
if (letterSpacing != 0 && isTextType && ((UITextView*)self).font != nil) {
19+
NSNumber *kern = [NSNumber numberWithDouble:letterSpacing * ((UITextView*)self).font.pointSize];
2020
attrDict[NSKernAttributeName] = kern;
2121
if ([self isKindOfClass:[UITextField class]]) {
2222
[((UITextField*)self).defaultTextAttributes setValue:kern forKey:NSKernAttributeName];
@@ -31,13 +31,13 @@ - (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration
3131
if ([self isKindOfClass:[UIButton class]]) {
3232
paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment;
3333

34-
if (((UIButton*)self).titleLabel.font) {
34+
if (((UIButton*)self).titleLabel.font != nil) {
3535
paragraphStyle.lineSpacing = fmax(lineHeight - ((UIButton*)self).titleLabel.font.lineHeight, 0);
3636
}
3737
} else {
3838
paragraphStyle.alignment = ((UILabel*)self).textAlignment;
3939

40-
if (((UILabel*)self).font) {
40+
if (((UILabel*)self).font != nil) {
4141
paragraphStyle.lineSpacing = fmax(lineHeight - ((UILabel*)self).font.lineHeight, 0);
4242
}
4343
}
@@ -86,7 +86,7 @@ - (void)nativeScriptSetTextDecorationAndTransform:(NSString*)text textDecoration
8686
-(void)nativeScriptSetFormattedTextDecorationAndTransform:(NSDictionary*)details letterSpacing:(CGFloat)letterSpacing lineHeight:(CGFloat)lineHeight {
8787
NSMutableAttributedString *attrText = [NativeScriptUtils createMutableStringWithDetails:details];
8888
if (letterSpacing != 0) {
89-
NSNumber *kern = [NSNumber numberWithDouble:letterSpacing];
89+
NSNumber *kern = [NSNumber numberWithDouble:letterSpacing * ((UITextView*)self).font.pointSize];
9090
[attrText addAttribute:NSKernAttributeName value:kern range:(NSRange){
9191
0,
9292
attrText.length
@@ -101,14 +101,14 @@ -(void)nativeScriptSetFormattedTextDecorationAndTransform:(NSDictionary*)details
101101
if ([self isKindOfClass:[UIButton class]]) {
102102
paragraphStyle.alignment = ((UIButton*)self).titleLabel.textAlignment;
103103

104-
if (((UIButton*)self).titleLabel.font) {
104+
if (((UIButton*)self).titleLabel.font != nil) {
105105
paragraphStyle.lineSpacing = fmax(lineHeight - ((UIButton*)self).titleLabel.font.lineHeight, 0);
106106
}
107107
} else {
108108
// Paragraph alignment is also important for tappable spans as NSTextContainer takes it into account
109109
paragraphStyle.alignment = ((UILabel*)self).textAlignment;
110110

111-
if (((UILabel*)self).font) {
111+
if (((UILabel*)self).font != nil) {
112112
paragraphStyle.lineSpacing = fmax(lineHeight - ((UILabel*)self).font.lineHeight, 0);
113113
}
114114
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,6 @@ export class TextBase extends TextBaseCommon {
365365
[fontSizeProperty.setNative](value: number) {
366366
if (!this.formattedText) {
367367
this.nativeTextViewProtected.setTextSize(value);
368-
369-
// Re-calculate letter-spacing
370-
if (this.letterSpacing != 0) {
371-
this._updateLetterSpacing(this.letterSpacing);
372-
}
373368
}
374369
}
375370

@@ -451,10 +446,10 @@ export class TextBase extends TextBaseCommon {
451446
}
452447

453448
[letterSpacingProperty.getDefault](): number {
454-
return org.nativescript.widgets.ViewHelper.getLetterspacing(this.nativeTextViewProtected) * this.fontSize;
449+
return org.nativescript.widgets.ViewHelper.getLetterspacing(this.nativeTextViewProtected);
455450
}
456451
[letterSpacingProperty.setNative](value: number) {
457-
this._updateLetterSpacing(value);
452+
org.nativescript.widgets.ViewHelper.setLetterspacing(this.nativeTextViewProtected, value);
458453
}
459454

460455
[paddingTopProperty.getDefault](): CoreTypes.LengthType {
@@ -503,11 +498,6 @@ export class TextBase extends TextBaseCommon {
503498
}
504499
}
505500

506-
_updateLetterSpacing(value: number): void {
507-
const emValue = value / this.fontSize;
508-
org.nativescript.widgets.ViewHelper.setLetterspacing(this.nativeTextViewProtected, emValue);
509-
}
510-
511501
_setNativeText(reset = false): void {
512502
if (reset) {
513503
this.nativeTextViewProtected.setText(null);

0 commit comments

Comments
 (0)