@@ -24,6 +24,12 @@ public CustomLineHeightSpan(float height) {
24
24
@ Override
25
25
public void chooseHeight (
26
26
CharSequence text , int start , int end , int spanstartv , int v , Paint .FontMetricsInt fm ) {
27
+
28
+ if (OVERRIDE_LINE_HEIGHT ) {
29
+ overrideLineHeight (fm );
30
+ return ;
31
+ }
32
+
27
33
// This is more complicated that I wanted it to be. You can find a good explanation of what the
28
34
// FontMetrics mean here: http://stackoverflow.com/questions/27631736.
29
35
// The general solution is that if there's not enough height to show the full line height, we
@@ -56,4 +62,41 @@ public void chooseHeight(
56
62
fm .descent = fm .bottom ;
57
63
}
58
64
}
65
+
66
+ private final static boolean OVERRIDE_LINE_HEIGHT = true ;
67
+
68
+ /**
69
+ * Discord Story time!
70
+ *
71
+ * So since we decided to be _very_ flexible with channel names, users have decided that they were gonna name their channels
72
+ * shit like ‧͙⁺˚・༓☾text☽༓・˚⁺‧͙ | l̶̟̦͚͎̦͑̎m̵̮̥̫͕͚̜̱̫̺̪͍̯̉̂̔͌́̚̕a̶͖̫͍͇̯̯̭͎͋̅́̿́̕͘͘͝͝ò̶̧̢͎̃̋͆̉͠ | and other fun non-standard channel names.
73
+ *
74
+ * This caused issues with line heights, because the RN implementation decided that it would try as best as possible to
75
+ * fit the text within the lineHeight that was given to it by the react component, causing text to be shifted upward
76
+ * and look terrible (see: https://canary.discord.com/channels/281683040739262465/912423796915462154/101286117376867126
77
+ * for an example).
78
+ *
79
+ * We (Jerry + Charles) decided that to fix this issue, we would instead ignore lineHeights _only_ if the text
80
+ * height was larger than the lineHeight provided to it.
81
+ *
82
+ * This is a much simpler implementation that what was previously here.
83
+ *
84
+ * _IF_ the lineHeight is larger than the text height, we default to centering the text as much as possible within
85
+ * that line height.
86
+ */
87
+ private void overrideLineHeight (Paint .FontMetricsInt fm ) {
88
+ int realTextHeight = fm .bottom - fm .top ;
89
+
90
+ if (mHeight >= realTextHeight ) {
91
+ // Show proportionally additional ascent / top & descent / bottom
92
+ final int additional = mHeight - (-fm .top + fm .bottom );
93
+
94
+ // Round up for the negative values and down for the positive values (arbitrary choice)
95
+ // So that bottom - top equals additional even if it's an odd number.
96
+ fm .top -= Math .ceil (additional / 2.0f );
97
+ fm .bottom += Math .floor (additional / 2.0f );
98
+ fm .ascent = fm .top ;
99
+ fm .descent = fm .bottom ;
100
+ }
101
+ }
59
102
}
0 commit comments