@@ -38,6 +38,8 @@ public class CustomStyleSpan extends MetricAffectingSpan implements ReactSpan {
3838 private final String mCurrentText ;
3939 private String mTextAlignVertical ;
4040 private int mHighestLineHeight ;
41+ private int mLineHeight ;
42+ private int mLineCount ;
4143
4244 public CustomStyleSpan (
4345 int fontStyle ,
@@ -67,7 +69,8 @@ public void updateDrawState(TextPaint ds) {
6769 mAssetManager ,
6870 mTextAlignVertical ,
6971 mCurrentText ,
70- mHighestLineHeight );
72+ mHighestLineHeight ,
73+ mLineHeight );
7174 }
7275
7376 @ Override
@@ -81,7 +84,8 @@ public void updateMeasureState(TextPaint paint) {
8184 mAssetManager ,
8285 mTextAlignVertical ,
8386 mCurrentText ,
84- mHighestLineHeight );
87+ mHighestLineHeight ,
88+ mLineHeight );
8589 }
8690
8791 public int getStyle () {
@@ -105,7 +109,8 @@ private static void apply(
105109 AssetManager assetManager ,
106110 @ Nullable String textAlignVertical ,
107111 String currentText ,
108- int highestLineHeight ) {
112+ int highestLineHeight ,
113+ int lineHeight ) {
109114 Typeface typeface =
110115 ReactTypefaceUtils .applyStyles (paint .getTypeface (), style , weight , family , assetManager );
111116 paint .setFontFeatureSettings (fontFeatureSettings );
@@ -119,33 +124,39 @@ private static void apply(
119124 if (highestLineHeight != 0 ) {
120125 // the span with the highest lineHeight sets the height for all rows
121126 paint .baselineShift -= highestLineHeight / 2 - paint .getTextSize () / 2 ;
127+ } else if (lineHeight > 0 ) {
128+ paint .baselineShift -= lineHeight / 2 - paint .getTextSize () / 2 ;
122129 } else {
123130 // works only with single line and without fontSize
124131 // https://bit.ly/3W2eJKT
125132 // if lineHeight is not set, align the text using the font metrics
126133 // 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;
133140 }
134141 }
135142 if (textAlignVertical == "bottom-child" ) {
136143 if (highestLineHeight != 0 ) {
137144 // the span with the highest lineHeight sets the height for all rows
138145 paint .baselineShift += highestLineHeight / 2 - paint .getTextSize () / 2 ;
146+ } else if (lineHeight > 0 ) {
147+ paint .baselineShift += lineHeight / 2 - paint .getTextSize () / 2 ;
139148 } else {
140149 // works only with single line and without fontSize
141150 // https://bit.ly/3W2eJKT
142- paint .baselineShift += paint .getFontMetrics ().bottom - paint .descent ();
151+ // paint.baselineShift += paint.getFontMetrics().bottom - paint.descent();
143152 }
144153 }
145154 }
146155 }
147156
148- public void updateSpan (int highestLineHeight ) {
157+ public void updateSpan (int highestLineHeight , int lineCount , int lineHeight ) {
149158 mHighestLineHeight = highestLineHeight ;
159+ mLineCount = lineCount ;
160+ mLineHeight = lineHeight ;
150161 }
151162}
0 commit comments