From b152934c30cf0ec02719bacd2ae4bef7f02236c4 Mon Sep 17 00:00:00 2001 From: abbo Date: Mon, 2 Nov 2026 11:39:14 -0800 Subject: [PATCH 1/2] Generated from a GitHub Pull Request. Run 'jf sync' on this diff to load the correct commit data. Differential Revision: D129144546 --- .../com/facebook/react/views/text/ReactTextView.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index 451677c8d1f1..20b45e9f8f01 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -289,6 +289,15 @@ protected void onDraw(Canvas canvas) { if (spanned != null) { Layout layout = getLayout(); + if (layout == null && getWidth() > 0 && getHeight() > 0) { + // setText drops the Layout and Fabric re-measures only on a frame change, so a text + // update that kept the frame reaches onDraw without one and the effects below would be + // skipped. Rebuild it here; TextView.onDraw would build one for the text anyway. + measure( + MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); + layout = getLayout(); + } if (layout != null) { CanvasEffectSpan[] drawSpans = spanned.getSpans(0, spanned.length(), CanvasEffectSpan.class); From 11b09bdb847569cf34b2c60c40dd9ef933baa5be Mon Sep 17 00:00:00 2001 From: Peter Abbondanzo Date: Mon, 2 Nov 2026 14:45:03 -0800 Subject: [PATCH 2/2] Add ReactTextView regression test for effect spans without remeasure Summary: A frame-preserving text update can reach `ReactTextView.onDraw` without a `Layout`, in which case effect spans (underline, strikethrough) were skipped and only plain text painted. This pins the corrected behavior: after `setText` carrying an effect span with no intervening measure, drawing still invokes the span hooks. Changelog: [Internal] Differential Revision: D129186364 --- .../react/views/text/ReactTextViewTest.kt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextViewTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextViewTest.kt index 1ddd04fb2aa7..971ffad97322 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextViewTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextViewTest.kt @@ -12,6 +12,7 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint +import android.text.Layout import android.text.SpannableString import android.text.Spanned import android.text.TextPaint @@ -27,6 +28,7 @@ import com.facebook.react.bridge.JavaOnlyArray import com.facebook.react.bridge.JavaOnlyMap import com.facebook.react.uimanager.DisplayMetricsHolder import com.facebook.react.uimanager.ReactStylesDiffMap +import com.facebook.react.views.text.internal.span.CanvasEffectSpan import com.facebook.react.views.text.internal.span.ReactAbsoluteSizeSpan import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -130,6 +132,39 @@ class ReactTextViewTest { assertThat(view.letterSpacing).isEqualTo(expectedLetterSpacing) } + @Test + fun effectSpansPaintAfterFramePreservingUpdateWithoutRemeasure() { + val width = 200 + val height = 100 + val view = TestReactTextView(RuntimeEnvironment.getApplication()) + view.layoutParams = + ViewGroup.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + ) + view.setTextColor(Color.BLACK) + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24f) + val plain = SpannableString("Hello") + view.setSpanned(plain) + view.text = plain + view.measure( + View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY), + ) + view.layout(0, 0, width, height) + assertThat(view.layout).isNotNull() + + val span = RecordingCanvasEffectSpan() + val decorated = SpannableString("Hello") + decorated.setSpan(span, 0, decorated.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + view.setSpanned(decorated) + view.text = decorated + view.drawTextForTest(Canvas(createBitmap(width, height))) + + assertThat(view.layout).isNotNull() + assertThat(span.drawCalls + span.preDrawCalls).isGreaterThan(0) + } + @Test fun drawsGlyphInkOutsideLineHeightWhenOverflowIsVisible() { val bitmap = drawReactTextViewWithOverflow(null) @@ -351,6 +386,19 @@ class ReactTextViewTest { } } + private class RecordingCanvasEffectSpan : CanvasEffectSpan() { + var preDrawCalls = 0 + var drawCalls = 0 + + override fun onPreDraw(start: Int, end: Int, canvas: Canvas, layout: Layout) { + preDrawCalls++ + } + + override fun onDraw(start: Int, end: Int, canvas: Canvas, layout: Layout) { + drawCalls++ + } + } + private class OverflowingInkSpan(private val lineHeight: Int) : ReplacementSpan() { override fun getSize( paint: Paint,