Commit 7e00154
committed
fix(android): track vertical gravity in DrawCommandSpan draw offset
The DrawCommandSpan draw block in `ReactTextView.onDraw` translated by
`getCompoundPaddingLeft(), getExtendedPaddingTop()` only, which works
for the default `Gravity.TOP` text alignment. When `textAlignVertical`
is `center` or `bottom` and the text is shorter than the view, the
glyphs are positioned by `super.onDraw` with an additional gravity
offset that the span draws were missing — so colored
underline/strikethrough rendered at the top of the view while the text
itself was vertically centered or bottom-aligned.
Recompute the offset locally (mirroring TextView.getVerticalOffset(),
which is private upstream) and add it to the translate before invoking
the span draws.
## Changelog
[ANDROID] [FIXED] - Custom text decorations track `textAlignVertical`
## Test Plan
Render a `<Text style={{ height: 200, textAlignVertical: 'center', textDecorationLine: 'underline', textDecorationColor: '#ff00aa', fontSize: 24 }}>Hello</Text>` inside a fixed-height parent and verify the magenta underline sits flush under "Hello" in the vertical center. Repeat with `textAlignVertical: 'bottom'`. Both now track the text; previously the underline stayed at the top of the box. Verified on Android API 36 emulator.1 parent 8f291a3 commit 7e00154
1 file changed
Lines changed: 18 additions & 1 deletion
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
224 | 241 | | |
225 | | - | |
| 242 | + | |
226 | 243 | | |
227 | 244 | | |
228 | 245 | | |
| |||
0 commit comments