Skip to content

Commit e59529d

Browse files
committed
update PR based on facebook#35949
1 parent 95324ec commit e59529d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,18 @@ private static void apply(
142142
return;
143143
}
144144

145+
// https://stackoverflow.com/a/27631737/7295772
146+
// top ------------- -10
147+
// ascent ------------- -5
148+
// baseline __my Text____ 0
149+
// descent _____________ 2
150+
// bottom _____________ 5
145151
TextPaint textPaintCopy = new TextPaint();
146152
textPaintCopy.set(ds);
147153
if (textSize > 0) {
148154
textPaintCopy.setTextSize(textSize);
149155
}
156+
150157
if (textSize == highestFontSize) {
151158
// aligns text vertically in the lineHeight
152159
// and adjust their position depending on the fontSize
@@ -163,6 +170,9 @@ private static void apply(
163170
ds.baselineShift -=
164171
highestLineHeight / 2
165172
- highestFontSize / 2
173+
// smaller font aligns on the baseline of bigger font
174+
// moves the baseline of text with smaller font up
175+
// so it aligns on the top of the larger font
166176
+ (highestFontSize - textSize)
167177
+ (textPaintCopy.getFontMetrics().top - textPaintCopy.ascent());
168178
}

0 commit comments

Comments
 (0)