Skip to content

Commit 00dbe53

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Cleanup Paper Handling of Inline Images and Padding in Text Components (#55437)
Summary: This deletes some Paper specific paths in Text and image code, related to inline view handling (done in native component layer in Paper), and how padding is set. It also changed `Spannable` to `Spanned` in a couple places, in preparation of reusing `ReactTextViewManager` with state generated by Facsimile (for selectable text). I left the actions performed by Paper ShadowNode as something stublike, since that code should never be executed. `ReactTextUpdate` is made internal, since the shape of native component state is subject to change. Changelog: [Android][Breaking] - Make ReactTextUpdate internal Differential Revision: D92459725
1 parent 29c7d7c commit 00dbe53

File tree

11 files changed

+16
-456
lines changed

11 files changed

+16
-456
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6181,44 +6181,17 @@ public final class com/facebook/react/views/text/ReactTextShadowNode : com/faceb
61816181
public final fun setShouldNotifyOnTextLayout (Z)V
61826182
}
61836183

6184-
public final class com/facebook/react/views/text/ReactTextUpdate {
6185-
public static final field Companion Lcom/facebook/react/views/text/ReactTextUpdate$Companion;
6186-
public fun <init> (Landroid/text/Spannable;IZFFFFI)V
6187-
public fun <init> (Landroid/text/Spannable;IZFFFFIII)V
6188-
public fun <init> (Landroid/text/Spannable;IZIII)V
6189-
public static final fun buildReactTextUpdateFromState (Landroid/text/Spannable;IIII)Lcom/facebook/react/views/text/ReactTextUpdate;
6190-
public final fun containsImages ()Z
6191-
public final fun getContainsImages ()Z
6192-
public final fun getJsEventCounter ()I
6193-
public final fun getJustificationMode ()I
6194-
public final fun getPaddingBottom ()F
6195-
public final fun getPaddingLeft ()F
6196-
public final fun getPaddingRight ()F
6197-
public final fun getPaddingTop ()F
6198-
public final fun getText ()Landroid/text/Spannable;
6199-
public final fun getTextAlign ()I
6200-
public final fun getTextBreakStrategy ()I
6201-
}
6202-
6203-
public final class com/facebook/react/views/text/ReactTextUpdate$Companion {
6204-
public final fun buildReactTextUpdateFromState (Landroid/text/Spannable;IIII)Lcom/facebook/react/views/text/ReactTextUpdate;
6205-
}
6206-
62076184
public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/widget/AppCompatTextView, com/facebook/react/uimanager/ReactCompoundView {
62086185
public fun <init> (Landroid/content/Context;)V
62096186
protected fun dispatchHoverEvent (Landroid/view/MotionEvent;)Z
62106187
public fun dispatchKeyEvent (Landroid/view/KeyEvent;)Z
62116188
public fun getSpanned ()Landroid/text/Spannable;
62126189
public fun hasOverlappingRendering ()Z
6213-
public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V
62146190
public fun onAttachedToWindow ()V
6215-
public fun onDetachedFromWindow ()V
62166191
protected fun onDraw (Landroid/graphics/Canvas;)V
6217-
public fun onFinishTemporaryDetach ()V
62186192
public final fun onFocusChanged (ZILandroid/graphics/Rect;)V
62196193
protected fun onLayout (ZIIII)V
62206194
protected fun onMeasure (II)V
6221-
public fun onStartTemporaryDetach ()V
62226195
public fun reactTagForTouch (FF)I
62236196
public fun setAdjustFontSizeToFit (Z)V
62246197
public fun setBackgroundColor (I)V
@@ -6241,7 +6214,6 @@ public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/wi
62416214
public fun setText (Lcom/facebook/react/views/text/ReactTextUpdate;)V
62426215
public fun setTextIsSelectable (Z)V
62436216
public fun updateView ()V
6244-
protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z
62456217
}
62466218

62476219
public final class com/facebook/react/views/text/ReactTextViewManager : com/facebook/react/views/text/ReactTextAnchorViewManager, com/facebook/react/uimanager/IViewManagerWithChildren, com/facebook/react/views/text/ReactTextViewManagerCallback {
@@ -6392,7 +6364,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
63926364
public final fun canUpdateWithEventCount (I)Z
63936365
protected final fun finalize ()V
63946366
public final fun getBorderColor (I)I
6395-
protected final fun getContainsImages ()Z
63966367
public final fun getDisableFullscreenUI ()Z
63976368
public final fun getDragAndDropFilter ()Ljava/util/List;
63986369
protected final fun getNativeEventCount ()I
@@ -6402,27 +6373,21 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
64026373
public final fun getSubmitBehavior ()Ljava/lang/String;
64036374
protected final fun hideSoftKeyboard ()V
64046375
public final fun incrementAndGetEventCounter ()I
6405-
public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V
64066376
public fun isLayoutRequested ()Z
64076377
protected final fun isSettingTextFromJS ()Z
64086378
protected final fun isSettingTextFromState ()Z
64096379
public final fun maybeSetSelection (III)V
6410-
public final fun maybeSetTextFromJS (Lcom/facebook/react/views/text/ReactTextUpdate;)V
6411-
public final fun maybeSetTextFromState (Lcom/facebook/react/views/text/ReactTextUpdate;)V
64126380
public final fun maybeUpdateTypeface ()V
64136381
public fun onAttachedToWindow ()V
64146382
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
64156383
public fun onCreateInputConnection (Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;
6416-
public fun onDetachedFromWindow ()V
64176384
public fun onDragEvent (Landroid/view/DragEvent;)Z
64186385
public fun onDraw (Landroid/graphics/Canvas;)V
6419-
public fun onFinishTemporaryDetach ()V
64206386
protected fun onFocusChanged (ZILandroid/graphics/Rect;)V
64216387
public fun onKeyUp (ILandroid/view/KeyEvent;)Z
64226388
protected fun onLayout (ZIIII)V
64236389
protected fun onScrollChanged (IIII)V
64246390
protected fun onSelectionChanged (II)V
6425-
public fun onStartTemporaryDetach ()V
64266391
public fun onTextContextMenuItem (I)Z
64276392
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
64286393
public fun removeTextChangedListener (Landroid/text/TextWatcher;)V
@@ -6435,7 +6400,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
64356400
public final fun setBorderRadius (FI)V
64366401
public final fun setBorderStyle (Ljava/lang/String;)V
64376402
public final fun setBorderWidth (IF)V
6438-
protected final fun setContainsImages (Z)V
64396403
public final fun setContentSizeWatcher (Lcom/facebook/react/views/textinput/ContentSizeWatcher;)V
64406404
public final fun setContextMenuHidden (Z)V
64416405
public final fun setDisableFullscreenUI (Z)V
@@ -6466,7 +6430,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
64666430
public final fun shouldBlurOnReturn ()Z
64676431
public final fun shouldSubmitOnReturn ()Z
64686432
protected final fun showSoftKeyboard ()Z
6469-
protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z
64706433
}
64716434

64726435
public final class com/facebook/react/views/textinput/ReactEditText$Companion {

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.facebook.react.uimanager.PixelUtil.toPixelFromDIP
2727
import com.facebook.react.uimanager.ReactAccessibilityDelegate
2828
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole
2929
import com.facebook.react.uimanager.ReactShadowNode
30-
import com.facebook.react.uimanager.ReactShadowNodeImpl
3130
import com.facebook.react.uimanager.ViewProps
3231
import com.facebook.react.uimanager.annotations.ReactProp
3332
import com.facebook.react.views.text.ReactTypefaceUtils.parseFontStyle
@@ -46,7 +45,6 @@ import com.facebook.react.views.text.internal.span.ReactTagSpan
4645
import com.facebook.react.views.text.internal.span.ReactUnderlineSpan
4746
import com.facebook.react.views.text.internal.span.SetSpanOperation
4847
import com.facebook.react.views.text.internal.span.ShadowStyleSpan
49-
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
5048
import com.facebook.react.views.text.internal.span.TextInlineViewPlaceholderSpan
5149
import com.facebook.yoga.YogaDirection
5250
import com.facebook.yoga.YogaUnit
@@ -199,36 +197,6 @@ public constructor(
199197
// or images.
200198
for (priorityIndex in ops.indices) {
201199
val op = ops[ops.size - priorityIndex - 1]
202-
val what = op.what
203-
204-
val isInlineImage = what is TextInlineImageSpan
205-
if (isInlineImage || what is TextInlineViewPlaceholderSpan) {
206-
val height: Int
207-
if (isInlineImage) {
208-
height = what.height
209-
textShadowNode.containsImages = true
210-
} else {
211-
val placeholder = what as TextInlineViewPlaceholderSpan
212-
height = placeholder.height
213-
214-
// Inline views cannot be layout-only because ReactTextView needs to access
215-
// them on the UI thread to measure and position them.
216-
val childNode = checkNotNull(inlineViews)[placeholder.reactTag]
217-
218-
checkNotNull(childNode)
219-
checkNotNull(nativeViewHierarchyOptimizer)
220-
nativeViewHierarchyOptimizer.handleForceViewToBeNonLayoutOnly(childNode)
221-
222-
// The ReactTextView is responsible for laying out the inline views.
223-
@Suppress("UNCHECKED_CAST")
224-
(childNode as ReactShadowNode<ReactShadowNodeImpl>).setLayoutParent(textShadowNode)
225-
}
226-
227-
if (heightOfTallestInlineViewOrImage.isNaN() || height > heightOfTallestInlineViewOrImage) {
228-
heightOfTallestInlineViewOrImage = height.toFloat()
229-
}
230-
}
231-
232200
// Actual order of calling `execute` does NOT matter,
233201
// but the `priorityIndex` DOES matter.
234202
op.execute(sb, priorityIndex)
@@ -533,17 +501,6 @@ public constructor(
533501
inlineViews,
534502
sb.length,
535503
)
536-
} else if (child is com.facebook.react.views.text.internal.ReactTextInlineImageShadowNode) {
537-
// We make the image take up 1 character in the span and put a corresponding character
538-
// into the text so that the image doesn't run over any following text.
539-
sb.append(INLINE_VIEW_PLACEHOLDER)
540-
ops.add(
541-
SetSpanOperation(
542-
sb.length - INLINE_VIEW_PLACEHOLDER.length,
543-
sb.length,
544-
child.buildInlineImageSpan(),
545-
)
546-
)
547504
} else if (supportsInlineViews) {
548505
val reactTag = child.reactTag
549506
val widthValue = child.styleWidth

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
2828
import com.facebook.react.uimanager.NativeViewHierarchyOptimizer
2929
import com.facebook.react.uimanager.PixelUtil
3030
import com.facebook.react.uimanager.ReactShadowNode
31-
import com.facebook.react.uimanager.Spacing
3231
import com.facebook.react.uimanager.UIViewOperationQueue
3332
import com.facebook.react.uimanager.annotations.ReactProp
3433
import com.facebook.react.uimanager.events.RCTEventEmitter
@@ -317,11 +316,6 @@ public constructor(reactTextViewManagerCallback: ReactTextViewManagerCallback? =
317316
ReactTextUpdate(
318317
text,
319318
ReactConstants.UNSET,
320-
containsImages,
321-
getPadding(Spacing.START),
322-
getPadding(Spacing.TOP),
323-
getPadding(Spacing.END),
324-
getPadding(Spacing.BOTTOM),
325319
_textAlign,
326320
textBreakStrategy,
327321
justificationMode,

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

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,20 @@
77

88
package com.facebook.react.views.text
99

10-
import android.text.Layout
11-
import android.text.Spannable
12-
import com.facebook.react.common.ReactConstants
10+
import android.text.Spanned
1311

1412
/** Class that contains the data needed for a text update. Used by both <Text/> and <TextInput/>. */
15-
public class ReactTextUpdate(
16-
public val text: Spannable,
13+
internal class ReactTextUpdate(
14+
public val text: Spanned,
1715
public val jsEventCounter: Int,
18-
public val containsImages: Boolean,
19-
public val paddingLeft: Float,
20-
public val paddingTop: Float,
21-
public val paddingRight: Float,
22-
public val paddingBottom: Float,
2316
public val textAlign: Int,
2417
public val textBreakStrategy: Int,
2518
public val justificationMode: Int,
2619
) {
27-
28-
/**
29-
* @deprecated Use a non-deprecated constructor for ReactTextUpdate instead. This one remains
30-
* because it's being used by a unit test that isn't currently open source.
31-
*/
32-
public constructor(
33-
text: Spannable,
34-
jsEventCounter: Int,
35-
containsImages: Boolean,
36-
paddingStart: Float,
37-
paddingTop: Float,
38-
paddingEnd: Float,
39-
paddingBottom: Float,
40-
textAlign: Int,
41-
) : this(
42-
text,
43-
jsEventCounter,
44-
containsImages,
45-
paddingStart,
46-
paddingTop,
47-
paddingEnd,
48-
paddingBottom,
49-
textAlign,
50-
Layout.BREAK_STRATEGY_HIGH_QUALITY,
51-
Layout.JUSTIFICATION_MODE_NONE,
52-
)
53-
54-
public constructor(
55-
text: Spannable,
56-
jsEventCounter: Int,
57-
containsImages: Boolean,
58-
textAlign: Int,
59-
textBreakStrategy: Int,
60-
justificationMode: Int,
61-
) : this(
62-
text,
63-
jsEventCounter,
64-
containsImages,
65-
ReactConstants.UNSET.toFloat(),
66-
ReactConstants.UNSET.toFloat(),
67-
ReactConstants.UNSET.toFloat(),
68-
ReactConstants.UNSET.toFloat(),
69-
textAlign,
70-
textBreakStrategy,
71-
justificationMode,
72-
)
73-
74-
@Deprecated(
75-
"This is just for backwards compatibility and will be removed some time in the future",
76-
ReplaceWith("containsImages"),
77-
)
78-
public fun containsImages(): Boolean = containsImages
79-
8020
public companion object {
8121
@JvmStatic
8222
public fun buildReactTextUpdateFromState(
83-
text: Spannable,
23+
text: Spanned,
8424
jsEventCounter: Int,
8525
textAlign: Int,
8626
textBreakStrategy: Int,
@@ -89,7 +29,6 @@ public class ReactTextUpdate(
8929
ReactTextUpdate(
9030
text,
9131
jsEventCounter,
92-
false,
9332
textAlign,
9433
textBreakStrategy,
9534
justificationMode,

0 commit comments

Comments
 (0)