Skip to content

Commit 1b562bf

Browse files
committed
fix: lineHeight fix. Working with Labels and Canvas
1 parent e2051e4 commit 1b562bf

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/text/index-common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function getTransformedText(text: string, textTransform: CoreTypes.TextTr
100100
}
101101
}
102102

103-
export const cssProperty = (target: Object, key: string | symbol) => {
103+
export const cssProperty = (target: object, key: string | symbol) => {
104104
// property getter
105105
const getter = function () {
106106
return this.style[key];
@@ -300,7 +300,7 @@ export function overrideSpanAndFormattedString(useLightFormatString = true) {
300300
}
301301
};
302302
TextBase.prototype.createFormattedTextNative = function (value: LightFormattedString | FormattedString) {
303-
return createNativeAttributedString(value as any, undefined, this, this['autoFontSize'], this['fontSizeRatio']);
303+
return createNativeAttributedString(value as any, undefined, this, this['autoFontSize'], this['fontSizeRatio'], 1, true);
304304
};
305305
TextBase.prototype[colorProperty.setNative] = function (value) {
306306
if (value instanceof Color) {

src/text/index.android.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type ClickableSpan = new (owner: Span) => android.text.style.ClickableSpan;
1010
export function adjustMinMaxFontScale(value, view) {
1111
// Only for iOS
1212
}
13-
function formattedStringToNativeString(formattedString, parent?, parentView = formattedString.parent, density?,scaleLineHeight?) {
13+
function formattedStringToNativeString(formattedString, parent?, parentView = formattedString.parent, density?, scaleLineHeight?) {
1414
let maxFontSize = formattedString?.fontSize || parentView?.fontSize || 0;
1515
formattedString.spans.forEach((s) => {
1616
if (s.fontSize) {
@@ -22,7 +22,7 @@ function formattedStringToNativeString(formattedString, parent?, parentView = fo
2222
parent = formattedString;
2323
}
2424
formattedString.spans.forEach((s, index) => {
25-
const spanDetails = typeof s === 'string' ? s : spanToNativeString(s, parent, parentView, maxFontSize, index, density);
25+
const spanDetails = typeof s === 'string' ? s : spanToNativeString(s, parent, parentView, maxFontSize, index, density, scaleLineHeight);
2626
if (spanDetails) {
2727
options.push(spanDetails);
2828
}
@@ -69,7 +69,8 @@ function spanToNativeString(span, parent: any, parentView: any, maxFontSize?, in
6969
// console.log('text FONT_SIZE_FACTOR', FONT_SIZE_FACTOR, Screen.mainScreen.scale)
7070
verticalTextAlignment = span.verticalAlignment || parent?.verticalAlignment;
7171
}
72-
if (density === 1) {
72+
// this is only needed when used with Text/Label components. Not canvas
73+
if (scaleLineHeight) {
7374
lineHeightFactor = com.nativescript.text.Font.getFontSizeFactor(Utils.android.getApplicationContext());
7475
}
7576
let backgroundColor = span.backgroundColor || parent?.backgroundColor;

0 commit comments

Comments
 (0)