Repository navigation
Commit 7b6e790
authored
fix: paint Android text decorations when a text update keeps the view's frame
This is #58579 by @MatiPl01, a fix for a bug I found. Mati is no longer at Software Mansion, so I'm picking this up from my fork. Thanks Mati!
## Summary:
Since #56768 underline and strikethrough are painted by `ReactTextView.onDraw` through `CanvasEffectSpan`s, and only when `getLayout()` is non-null. `TextView.setText` drops the `Layout` and rebuilds it in `onMeasure`, but Fabric measures a view only when its frame changed. A text update that keeps the frame (`textDecorationLine` or `textDecorationColor` changing on a text that keeps its size) therefore reaches `onDraw` without a `Layout`, the decorations are skipped and `super.onDraw()` paints plain text; they show up only once something else re-measures the view.
`onDraw` now rebuilds the `Layout` at the current size before painting the effects; `TextView.onDraw` would build one for the text anyway.
## Changelog:
[ANDROID] [FIXED] - Draw text decorations after a text update that did not change the view's frame
## Test Plan:
Android emulator API 34, RN 0.88.0-rc.1. With logging in `onDraw`, every frame-preserving update arrived as `setText -> onDraw` with `getLayout() == null` and no decoration painted, both for `setState` toggling `textDecorationLine` and for a Reanimated animation updating it every frame; the same update followed by a frame change painted it.
`textDecorationLine` cycling `none` / `underline` / `line-through` / `underline line-through` every 0.75 s, before and after:
https://github.com/user-attachments/assets/7aecf0a9-f999-4f1b-9699-fd07be53cb53
Differential Revision: D129144546
Pull Request resolved: #588471 parent 875656a commit 7b6e790
1 file changed
Lines changed: 9 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
292 | 301 | | |
293 | 302 | | |
294 | 303 | | |
| |||
0 commit comments