@@ -38,6 +38,8 @@ public class CustomStyleSpan extends MetricAffectingSpan implements ReactSpan {
38
38
private final String mCurrentText ;
39
39
private String mTextAlignVertical ;
40
40
private int mHighestLineHeight ;
41
+ private int mLineHeight ;
42
+ private int mLineCount ;
41
43
42
44
public CustomStyleSpan (
43
45
int fontStyle ,
@@ -67,7 +69,8 @@ public void updateDrawState(TextPaint ds) {
67
69
mAssetManager ,
68
70
mTextAlignVertical ,
69
71
mCurrentText ,
70
- mHighestLineHeight );
72
+ mHighestLineHeight ,
73
+ mLineHeight );
71
74
}
72
75
73
76
@ Override
@@ -81,7 +84,8 @@ public void updateMeasureState(TextPaint paint) {
81
84
mAssetManager ,
82
85
mTextAlignVertical ,
83
86
mCurrentText ,
84
- mHighestLineHeight );
87
+ mHighestLineHeight ,
88
+ mLineHeight );
85
89
}
86
90
87
91
public int getStyle () {
@@ -105,7 +109,8 @@ private static void apply(
105
109
AssetManager assetManager ,
106
110
@ Nullable String textAlignVertical ,
107
111
String currentText ,
108
- int highestLineHeight ) {
112
+ int highestLineHeight ,
113
+ int lineHeight ) {
109
114
Typeface typeface =
110
115
ReactTypefaceUtils .applyStyles (paint .getTypeface (), style , weight , family , assetManager );
111
116
paint .setFontFeatureSettings (fontFeatureSettings );
@@ -119,33 +124,39 @@ private static void apply(
119
124
if (highestLineHeight != 0 ) {
120
125
// the span with the highest lineHeight sets the height for all rows
121
126
paint .baselineShift -= highestLineHeight / 2 - paint .getTextSize () / 2 ;
127
+ } else if (lineHeight > 0 ) {
128
+ paint .baselineShift -= lineHeight / 2 - paint .getTextSize () / 2 ;
122
129
} else {
123
130
// works only with single line and without fontSize
124
131
// https://bit.ly/3W2eJKT
125
132
// if lineHeight is not set, align the text using the font metrics
126
133
// https://stackoverflow.com/a/27631737/7295772
127
- // top ------------- -26
128
- // ascent ------------- -30
129
- // baseline __my Text____ 0
130
- // descent _____________ 8
131
- // bottom _____________ 1
132
- paint .baselineShift += paint .getFontMetrics ().top - paint .getFontMetrics ().ascent ;
134
+ // top -------------
135
+ // ascent -------------
136
+ // baseline __my Text____
137
+ // descent _____________
138
+ // bottom _____________
139
+ // paint.baselineShift += paint.getFontMetrics().top - paint.getFontMetrics().ascent;
133
140
}
134
141
}
135
142
if (textAlignVertical == "bottom-child" ) {
136
143
if (highestLineHeight != 0 ) {
137
144
// the span with the highest lineHeight sets the height for all rows
138
145
paint .baselineShift += highestLineHeight / 2 - paint .getTextSize () / 2 ;
146
+ } else if (lineHeight > 0 ) {
147
+ paint .baselineShift += lineHeight / 2 - paint .getTextSize () / 2 ;
139
148
} else {
140
149
// works only with single line and without fontSize
141
150
// https://bit.ly/3W2eJKT
142
- paint .baselineShift += paint .getFontMetrics ().bottom - paint .descent ();
151
+ // paint.baselineShift += paint.getFontMetrics().bottom - paint.descent();
143
152
}
144
153
}
145
154
}
146
155
}
147
156
148
- public void updateSpan (int highestLineHeight ) {
157
+ public void updateSpan (int highestLineHeight , int lineCount , int lineHeight ) {
149
158
mHighestLineHeight = highestLineHeight ;
159
+ mLineCount = lineCount ;
160
+ mLineHeight = lineHeight ;
150
161
}
151
162
}
0 commit comments