Skip to content

Commit bbe2e8c

Browse files
committed
fix(android): rebase onto CanvasEffectSpan rename
Upstream #56705 renamed DrawCommandSpan and dropped its `ReactSpan` marker; re-add the interface on the underline/strikethrough subclasses so `SetSpanOperation` still accepts them.
1 parent 7e00154 commit bbe2e8c

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.facebook.react.uimanager.style.BorderStyle;
4747
import com.facebook.react.uimanager.style.LogicalEdge;
4848
import com.facebook.react.uimanager.style.Overflow;
49-
import com.facebook.react.views.text.internal.span.DrawCommandSpan;
49+
import com.facebook.react.views.text.internal.span.CanvasEffectSpan;
5050
import com.facebook.react.views.text.internal.span.ReactFragmentIndexSpan;
5151
import com.facebook.react.views.text.internal.span.ReactTagSpan;
5252
import com.facebook.yoga.YogaMeasureMode;
@@ -218,13 +218,10 @@ protected void onDraw(Canvas canvas) {
218218
if (spanned != null) {
219219
Layout layout = getLayout();
220220
if (layout != null) {
221-
DrawCommandSpan[] drawSpans =
222-
spanned.getSpans(0, spanned.length(), DrawCommandSpan.class);
221+
CanvasEffectSpan[] drawSpans =
222+
spanned.getSpans(0, spanned.length(), CanvasEffectSpan.class);
223223
if (drawSpans.length > 0) {
224-
// Mirror TextView.getVerticalOffset() — it's private upstream so we
225-
// recompute the gravity-driven offset that `super.onDraw` applies
226-
// before painting glyphs. Without this the span draws would land at
227-
// the top of the view while text is centered or bottom-aligned.
224+
// TextView.getVerticalOffset() is private; recompute it here.
228225
int voffsetText = 0;
229226
if ((getGravity() & Gravity.VERTICAL_GRAVITY_MASK) != Gravity.TOP) {
230227
int boxHeight =
@@ -240,7 +237,7 @@ protected void onDraw(Canvas canvas) {
240237
}
241238
canvas.save();
242239
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop() + voffsetText);
243-
for (DrawCommandSpan span : drawSpans) {
240+
for (CanvasEffectSpan span : drawSpans) {
244241
int start = spanned.getSpanStart(span);
245242
int end = spanned.getSpanEnd(span);
246243
span.onDraw(start, end, canvas, layout);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/internal/span/ReactStrikethroughSpan.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.math.max
1515

1616
/**
1717
* Draws a strikethrough whose color may differ from the text color. Subclasses
18-
* [DrawCommandSpan] so [PreparedLayoutTextView] and [ReactTextView] invoke
18+
* [CanvasEffectSpan] so [PreparedLayoutTextView] and [ReactTextView] invoke
1919
* [onDraw] after the layout renders its text. We do NOT extend
2020
* [android.text.style.StrikethroughSpan] here: the framework's `Layout.draw`
2121
* paints the strikethrough using `paint.color` with no field to override,
@@ -26,7 +26,7 @@ import kotlin.math.max
2626
* text's foreground color, matching the platform's prior behavior.
2727
*/
2828
internal class ReactStrikethroughSpan(private val color: Int = Color.TRANSPARENT) :
29-
DrawCommandSpan() {
29+
CanvasEffectSpan(), ReactSpan {
3030

3131
override fun onDraw(start: Int, end: Int, canvas: Canvas, layout: Layout) {
3232
val paint = layout.paint

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/internal/span/ReactUnderlineSpan.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.math.max
1515

1616
/**
1717
* Draws an underline whose color may differ from the text color. Subclasses
18-
* [DrawCommandSpan] so [PreparedLayoutTextView] invokes [onDraw] after the
18+
* [CanvasEffectSpan] so [PreparedLayoutTextView] invokes [onDraw] after the
1919
* layout renders its text, ensuring the underline paints on top of any
2020
* descenders. We do NOT extend [android.text.style.UnderlineSpan] here:
2121
* the framework's `Layout.draw` reads `paint.color` for underline color
@@ -27,7 +27,7 @@ import kotlin.math.max
2727
* text's foreground color, matching the platform's prior behavior.
2828
*/
2929
internal class ReactUnderlineSpan(private val color: Int = Color.TRANSPARENT) :
30-
DrawCommandSpan() {
30+
CanvasEffectSpan(), ReactSpan {
3131

3232
override fun onDraw(start: Int, end: Int, canvas: Canvas, layout: Layout) {
3333
val paint = layout.paint

0 commit comments

Comments
 (0)