Skip to content

Commit c86e46f

Browse files
committed
Rebuild the TextView Layout before drawing text effects on Android
ReactTextView.onDraw paints CanvasEffectSpans (underline, strikethrough) only when getLayout() is non-null. TextView drops its Layout in setText and rebuilds it in onMeasure, and Fabric measures a view only when its frame changed, so a text state update that keeps the frame (a decoration or color change on a text of the same size) reaches onDraw with no Layout and the decorations are skipped until something else re-measures the view. Rebuild the Layout at the current size before painting; TextView.onDraw would build one for the plain text anyway.
1 parent a9307d8 commit c86e46f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ protected void onDraw(Canvas canvas) {
257257

258258
if (spanned != null) {
259259
Layout layout = getLayout();
260+
if (layout == null && getWidth() > 0 && getHeight() > 0) {
261+
// TextView drops its Layout in setText and rebuilds it in onMeasure, and Fabric measures
262+
// a view only when its frame changed. A text update that keeps the frame (a color or
263+
// decoration change, e.g. driven by an animation) therefore gets here with no Layout,
264+
// and the CanvasEffectSpans below would be skipped for that frame. Rebuild the Layout
265+
// at the current size first; TextView.onDraw would build one for the text anyway.
266+
measure(
267+
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
268+
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
269+
layout = getLayout();
270+
}
260271
if (layout != null) {
261272
CanvasEffectSpan[] drawSpans =
262273
spanned.getSpans(0, spanned.length(), CanvasEffectSpan.class);

0 commit comments

Comments
 (0)