mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Cleanup Paper Handling of Inline Images and Padding in Text Components (#55437)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55437 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 Reviewed By: javache Differential Revision: D92459725 fbshipit-source-id: e1bc0f9a19adbf296fb1873913f9db319eb8b3f9
This commit is contained in:
1 parent
66c603f57e
commit
faebee4338
8 files changed
+16
-402
No files matched your search
@@ -6133,44 +6133,17 @@ public final class com/facebook/react/views/text/ReactTextShadowNode : com/faceb
|
||||
public final fun setShouldNotifyOnTextLayout (Z)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/text/ReactTextUpdate {
|
||||
public static final field Companion Lcom/facebook/react/views/text/ReactTextUpdate$Companion;
|
||||
public fun <init> (Landroid/text/Spannable;IZFFFFI)V
|
||||
public fun <init> (Landroid/text/Spannable;IZFFFFIII)V
|
||||
public fun <init> (Landroid/text/Spannable;IZIII)V
|
||||
public static final fun buildReactTextUpdateFromState (Landroid/text/Spannable;IIII)Lcom/facebook/react/views/text/ReactTextUpdate;
|
||||
public final fun containsImages ()Z
|
||||
public final fun getContainsImages ()Z
|
||||
public final fun getJsEventCounter ()I
|
||||
public final fun getJustificationMode ()I
|
||||
public final fun getPaddingBottom ()F
|
||||
public final fun getPaddingLeft ()F
|
||||
public final fun getPaddingRight ()F
|
||||
public final fun getPaddingTop ()F
|
||||
public final fun getText ()Landroid/text/Spannable;
|
||||
public final fun getTextAlign ()I
|
||||
public final fun getTextBreakStrategy ()I
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/text/ReactTextUpdate$Companion {
|
||||
public final fun buildReactTextUpdateFromState (Landroid/text/Spannable;IIII)Lcom/facebook/react/views/text/ReactTextUpdate;
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/widget/AppCompatTextView, com/facebook/react/uimanager/ReactCompoundView {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
protected fun dispatchHoverEvent (Landroid/view/MotionEvent;)Z
|
||||
public fun dispatchKeyEvent (Landroid/view/KeyEvent;)Z
|
||||
public fun getSpanned ()Landroid/text/Spannable;
|
||||
public fun hasOverlappingRendering ()Z
|
||||
public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V
|
||||
public fun onAttachedToWindow ()V
|
||||
public fun onDetachedFromWindow ()V
|
||||
protected fun onDraw (Landroid/graphics/Canvas;)V
|
||||
public fun onFinishTemporaryDetach ()V
|
||||
public final fun onFocusChanged (ZILandroid/graphics/Rect;)V
|
||||
protected fun onLayout (ZIIII)V
|
||||
protected fun onMeasure (II)V
|
||||
public fun onStartTemporaryDetach ()V
|
||||
public fun reactTagForTouch (FF)I
|
||||
public fun setAdjustFontSizeToFit (Z)V
|
||||
public fun setBackgroundColor (I)V
|
||||
@@ -6193,7 +6166,6 @@ public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/wi
|
||||
public fun setText (Lcom/facebook/react/views/text/ReactTextUpdate;)V
|
||||
public fun setTextIsSelectable (Z)V
|
||||
public fun updateView ()V
|
||||
protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -6344,7 +6316,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
|
||||
public final fun canUpdateWithEventCount (I)Z
|
||||
protected final fun finalize ()V
|
||||
public final fun getBorderColor (I)I
|
||||
protected final fun getContainsImages ()Z
|
||||
public final fun getDisableFullscreenUI ()Z
|
||||
public final fun getDragAndDropFilter ()Ljava/util/List;
|
||||
protected final fun getNativeEventCount ()I
|
||||
@@ -6354,27 +6325,21 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
|
||||
public final fun getSubmitBehavior ()Ljava/lang/String;
|
||||
protected final fun hideSoftKeyboard ()V
|
||||
public final fun incrementAndGetEventCounter ()I
|
||||
public fun invalidateDrawable (Landroid/graphics/drawable/Drawable;)V
|
||||
public fun isLayoutRequested ()Z
|
||||
protected final fun isSettingTextFromJS ()Z
|
||||
protected final fun isSettingTextFromState ()Z
|
||||
public final fun maybeSetSelection (III)V
|
||||
public final fun maybeSetTextFromJS (Lcom/facebook/react/views/text/ReactTextUpdate;)V
|
||||
public final fun maybeSetTextFromState (Lcom/facebook/react/views/text/ReactTextUpdate;)V
|
||||
public final fun maybeUpdateTypeface ()V
|
||||
public fun onAttachedToWindow ()V
|
||||
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
|
||||
public fun onCreateInputConnection (Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;
|
||||
public fun onDetachedFromWindow ()V
|
||||
public fun onDragEvent (Landroid/view/DragEvent;)Z
|
||||
public fun onDraw (Landroid/graphics/Canvas;)V
|
||||
public fun onFinishTemporaryDetach ()V
|
||||
protected fun onFocusChanged (ZILandroid/graphics/Rect;)V
|
||||
public fun onKeyUp (ILandroid/view/KeyEvent;)Z
|
||||
protected fun onLayout (ZIIII)V
|
||||
protected fun onScrollChanged (IIII)V
|
||||
protected fun onSelectionChanged (II)V
|
||||
public fun onStartTemporaryDetach ()V
|
||||
public fun onTextContextMenuItem (I)Z
|
||||
public fun onTouchEvent (Landroid/view/MotionEvent;)Z
|
||||
public fun removeTextChangedListener (Landroid/text/TextWatcher;)V
|
||||
@@ -6387,7 +6352,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
|
||||
public final fun setBorderRadius (FI)V
|
||||
public final fun setBorderStyle (Ljava/lang/String;)V
|
||||
public final fun setBorderWidth (IF)V
|
||||
protected final fun setContainsImages (Z)V
|
||||
public final fun setContentSizeWatcher (Lcom/facebook/react/views/textinput/ContentSizeWatcher;)V
|
||||
public final fun setContextMenuHidden (Z)V
|
||||
public final fun setDisableFullscreenUI (Z)V
|
||||
@@ -6418,7 +6382,6 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
|
||||
public final fun shouldBlurOnReturn ()Z
|
||||
public final fun shouldSubmitOnReturn ()Z
|
||||
protected final fun showSoftKeyboard ()Z
|
||||
protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/textinput/ReactEditText$Companion {
|
||||
|
||||
+4
-65
@@ -7,80 +7,20 @@
|
||||
|
||||
package com.facebook.react.views.text
|
||||
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import com.facebook.react.common.ReactConstants
|
||||
import android.text.Spanned
|
||||
|
||||
/** Class that contains the data needed for a text update. Used by both <Text/> and <TextInput/>. */
|
||||
public class ReactTextUpdate(
|
||||
public val text: Spannable,
|
||||
internal class ReactTextUpdate(
|
||||
public val text: Spanned,
|
||||
public val jsEventCounter: Int,
|
||||
public val containsImages: Boolean,
|
||||
public val paddingLeft: Float,
|
||||
public val paddingTop: Float,
|
||||
public val paddingRight: Float,
|
||||
public val paddingBottom: Float,
|
||||
public val textAlign: Int,
|
||||
public val textBreakStrategy: Int,
|
||||
public val justificationMode: Int,
|
||||
) {
|
||||
|
||||
/**
|
||||
* @deprecated Use a non-deprecated constructor for ReactTextUpdate instead. This one remains
|
||||
* because it's being used by a unit test that isn't currently open source.
|
||||
*/
|
||||
public constructor(
|
||||
text: Spannable,
|
||||
jsEventCounter: Int,
|
||||
containsImages: Boolean,
|
||||
paddingStart: Float,
|
||||
paddingTop: Float,
|
||||
paddingEnd: Float,
|
||||
paddingBottom: Float,
|
||||
textAlign: Int,
|
||||
) : this(
|
||||
text,
|
||||
jsEventCounter,
|
||||
containsImages,
|
||||
paddingStart,
|
||||
paddingTop,
|
||||
paddingEnd,
|
||||
paddingBottom,
|
||||
textAlign,
|
||||
Layout.BREAK_STRATEGY_HIGH_QUALITY,
|
||||
Layout.JUSTIFICATION_MODE_NONE,
|
||||
)
|
||||
|
||||
public constructor(
|
||||
text: Spannable,
|
||||
jsEventCounter: Int,
|
||||
containsImages: Boolean,
|
||||
textAlign: Int,
|
||||
textBreakStrategy: Int,
|
||||
justificationMode: Int,
|
||||
) : this(
|
||||
text,
|
||||
jsEventCounter,
|
||||
containsImages,
|
||||
ReactConstants.UNSET.toFloat(),
|
||||
ReactConstants.UNSET.toFloat(),
|
||||
ReactConstants.UNSET.toFloat(),
|
||||
ReactConstants.UNSET.toFloat(),
|
||||
textAlign,
|
||||
textBreakStrategy,
|
||||
justificationMode,
|
||||
)
|
||||
|
||||
@Deprecated(
|
||||
"This is just for backwards compatibility and will be removed some time in the future",
|
||||
ReplaceWith("containsImages"),
|
||||
)
|
||||
public fun containsImages(): Boolean = containsImages
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
public fun buildReactTextUpdateFromState(
|
||||
text: Spannable,
|
||||
text: Spanned,
|
||||
jsEventCounter: Int,
|
||||
textAlign: Int,
|
||||
textBreakStrategy: Int,
|
||||
@@ -89,7 +29,6 @@ public class ReactTextUpdate(
|
||||
ReactTextUpdate(
|
||||
text,
|
||||
jsEventCounter,
|
||||
false,
|
||||
textAlign,
|
||||
textBreakStrategy,
|
||||
justificationMode,
|
||||
|
||||
+7
-98
@@ -10,10 +10,10 @@ package com.facebook.react.views.text;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
@@ -53,7 +53,6 @@ import com.facebook.react.uimanager.style.BorderStyle;
|
||||
import com.facebook.react.uimanager.style.LogicalEdge;
|
||||
import com.facebook.react.uimanager.style.Overflow;
|
||||
import com.facebook.react.views.text.internal.span.ReactTagSpan;
|
||||
import com.facebook.react.views.text.internal.span.TextInlineImageSpan;
|
||||
import com.facebook.react.views.text.internal.span.TextInlineViewPlaceholderSpan;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
|
||||
@@ -66,7 +65,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
// https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L854
|
||||
private static final int DEFAULT_GRAVITY = Gravity.TOP | Gravity.START;
|
||||
|
||||
private boolean mContainsImages;
|
||||
private int mNumberOfLines;
|
||||
private @Nullable TextUtils.TruncateAt mEllipsizeLocation;
|
||||
private boolean mAdjustsFontSizeToFit;
|
||||
@@ -377,38 +375,21 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
|
||||
public void setText(ReactTextUpdate update) {
|
||||
try (SystraceSection s = new SystraceSection("ReactTextView.setText(ReactTextUpdate)")) {
|
||||
mContainsImages = update.containsImages();
|
||||
// Android's TextView crashes when it tries to relayout if LayoutParams are
|
||||
// null; explicitly set the LayoutParams to prevent this crash. See:
|
||||
// https://github.com/facebook/react-native/pull/7011
|
||||
if (getLayoutParams() == null) {
|
||||
setLayoutParams(EMPTY_LAYOUT_PARAMS);
|
||||
}
|
||||
Spannable spannable = update.getText();
|
||||
Spanned spanned = update.getText();
|
||||
if (mLinkifyMaskType > 0) {
|
||||
Linkify.addLinks(spannable, mLinkifyMaskType);
|
||||
if (!(spanned instanceof Spannable)) {
|
||||
spanned = new SpannableString(spanned);
|
||||
}
|
||||
Linkify.addLinks((Spannable) spanned, mLinkifyMaskType);
|
||||
setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
setText(spannable);
|
||||
float paddingLeft = update.getPaddingLeft();
|
||||
float paddingTop = update.getPaddingTop();
|
||||
float paddingRight = update.getPaddingRight();
|
||||
float paddingBottom = update.getPaddingBottom();
|
||||
|
||||
// In Fabric padding is set by the update of Layout Metrics and not as part of the "setText"
|
||||
// operation
|
||||
// TODO T56559197: remove this condition when we migrate 100% to Fabric
|
||||
if (paddingLeft != ReactConstants.UNSET
|
||||
&& paddingTop != ReactConstants.UNSET
|
||||
&& paddingRight != ReactConstants.UNSET
|
||||
&& paddingBottom != ReactConstants.UNSET) {
|
||||
|
||||
setPadding(
|
||||
(int) Math.floor(paddingLeft),
|
||||
(int) Math.floor(paddingTop),
|
||||
(int) Math.floor(paddingRight),
|
||||
(int) Math.floor(paddingBottom));
|
||||
}
|
||||
setText(spanned);
|
||||
|
||||
int nextTextAlign = update.getTextAlign();
|
||||
if (nextTextAlign != getGravityHorizontal()) {
|
||||
@@ -481,58 +462,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable drawable) {
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
if (span.getDrawable() == drawable) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.verifyDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateDrawable(Drawable drawable) {
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
if (span.getDrawable() == drawable) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
super.invalidateDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
span.onDetachedFromWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTemporaryDetach() {
|
||||
super.onStartTemporaryDetach();
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
span.onStartTemporaryDetach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextIsSelectable(boolean selectable) {
|
||||
mTextIsSelectable = selectable;
|
||||
@@ -551,26 +480,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
} else {
|
||||
setTextIsSelectable(false);
|
||||
}
|
||||
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
span.onAttachedToWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishTemporaryDetach() {
|
||||
super.onFinishTemporaryDetach();
|
||||
if (mContainsImages && getText() instanceof Spanned) {
|
||||
Spanned text = (Spanned) getText();
|
||||
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
|
||||
for (TextInlineImageSpan span : spans) {
|
||||
span.onFinishTemporaryDetach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-8
@@ -9,6 +9,7 @@ package com.facebook.react.views.text
|
||||
|
||||
import android.os.Build
|
||||
import android.text.Spannable
|
||||
import android.text.Spanned
|
||||
import com.facebook.react.R
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer
|
||||
@@ -20,7 +21,6 @@ import com.facebook.react.uimanager.ReactStylesDiffMap
|
||||
import com.facebook.react.uimanager.StateWrapper
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.facebook.react.uimanager.annotations.ReactProp
|
||||
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
|
||||
import java.util.HashMap
|
||||
|
||||
/**
|
||||
@@ -75,17 +75,13 @@ public constructor(
|
||||
override fun updateExtraData(view: ReactTextView, extraData: Any) {
|
||||
SystraceSection("ReactTextViewManager.updateExtraData").use { s ->
|
||||
val update = extraData as ReactTextUpdate
|
||||
val spannable: Spannable = update.text
|
||||
@Suppress("DEPRECATION")
|
||||
if (update.containsImages()) {
|
||||
TextInlineImageSpan.possiblyUpdateInlineImageSpans(spannable, view)
|
||||
}
|
||||
val spanned: Spanned = update.text
|
||||
view.setText(update)
|
||||
|
||||
// If this text view contains any clickable spans, set a view tag and reset the accessibility
|
||||
// delegate so that these can be picked up by the accessibility system.
|
||||
val accessibilityLinks: ReactTextViewAccessibilityDelegate.AccessibilityLinks =
|
||||
ReactTextViewAccessibilityDelegate.AccessibilityLinks(spannable)
|
||||
ReactTextViewAccessibilityDelegate.AccessibilityLinks(spanned)
|
||||
view.setTag(
|
||||
R.id.accessibility_links,
|
||||
if (accessibilityLinks.size() > 0) accessibilityLinks else null,
|
||||
@@ -159,7 +155,6 @@ public constructor(
|
||||
return ReactTextUpdate(
|
||||
spanned,
|
||||
-1, // UNUSED FOR TEXT
|
||||
false, // TODO add this into local Data
|
||||
TextLayoutManager.getTextGravity(attributedString, spanned),
|
||||
textBreakStrategy,
|
||||
TextAttributeProps.getJustificationMode(props, currentJustificationMode),
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package com.facebook.react.views.text.internal
|
||||
|
||||
import com.facebook.react.common.annotations.internal.LegacyArchitecture
|
||||
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
|
||||
import com.facebook.react.uimanager.LayoutShadowNode
|
||||
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
|
||||
import com.facebook.yoga.YogaNode
|
||||
|
||||
/** Base class for [YogaNode]s that represent inline images. */
|
||||
@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR)
|
||||
@Deprecated(
|
||||
message = "This class is part of Legacy Architecture and will be removed in a future release",
|
||||
level = DeprecationLevel.WARNING,
|
||||
)
|
||||
internal abstract class ReactTextInlineImageShadowNode : LayoutShadowNode() {
|
||||
/**
|
||||
* Build a [TextInlineImageSpan] from this node. This will be added to the TextView in place of
|
||||
* this node.
|
||||
*/
|
||||
abstract fun buildInlineImageSpan(): TextInlineImageSpan
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.text.internal.span
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.Spannable
|
||||
import android.text.style.ReplacementSpan
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
|
||||
/** Base class for inline image spans. */
|
||||
internal abstract class TextInlineImageSpan : ReplacementSpan(), ReactSpan {
|
||||
/** Get the drawable that is span represents. */
|
||||
abstract val drawable: Drawable?
|
||||
|
||||
/** Called by the text view from [View.onDetachedFromWindow], */
|
||||
abstract fun onDetachedFromWindow()
|
||||
|
||||
/** Called by the text view from [View.onStartTemporaryDetach]. */
|
||||
abstract fun onStartTemporaryDetach()
|
||||
|
||||
/** Called by the text view from [View.onAttachedToWindow]. */
|
||||
abstract fun onAttachedToWindow()
|
||||
|
||||
/** Called by the text view from [View.onFinishTemporaryDetach]. */
|
||||
abstract fun onFinishTemporaryDetach()
|
||||
|
||||
/** Set the textview that will contain this span. */
|
||||
abstract fun setTextView(textView: TextView?)
|
||||
|
||||
/** Get the width of the span. */
|
||||
abstract val width: Int
|
||||
|
||||
/** Get the height of the span. */
|
||||
abstract val height: Int
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* For TextInlineImageSpan we need to update the Span to know that the window is attached and
|
||||
* the TextView that we will set as the callback on the Drawable.
|
||||
*
|
||||
* @param spannable The spannable that may contain TextInlineImageSpans
|
||||
* @param view The view which will be set as the callback for the Drawable
|
||||
*/
|
||||
@JvmStatic
|
||||
fun possiblyUpdateInlineImageSpans(spannable: Spannable, view: TextView?) {
|
||||
spannable.getSpans(0, spannable.length, TextInlineImageSpan::class.java).forEach { s ->
|
||||
s.onAttachedToWindow()
|
||||
s.setTextView(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-75
@@ -14,7 +14,6 @@ import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
@@ -86,7 +85,6 @@ import com.facebook.react.views.text.internal.span.ReactSpan
|
||||
import com.facebook.react.views.text.internal.span.ReactStrikethroughSpan
|
||||
import com.facebook.react.views.text.internal.span.ReactTextPaintHolderSpan
|
||||
import com.facebook.react.views.text.internal.span.ReactUnderlineSpan
|
||||
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
@@ -119,7 +117,6 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
private var listeners: CopyOnWriteArrayList<TextWatcher>?
|
||||
|
||||
public var stagedInputType: Int
|
||||
protected var containsImages: Boolean = false
|
||||
public var submitBehavior: String? = null
|
||||
public var dragAndDropFilter: List<String>? = null
|
||||
|
||||
@@ -639,13 +636,13 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
|
||||
public fun incrementAndGetEventCounter(): Int = ++nativeEventCount
|
||||
|
||||
public fun maybeSetTextFromJS(reactTextUpdate: ReactTextUpdate) {
|
||||
internal fun maybeSetTextFromJS(reactTextUpdate: ReactTextUpdate) {
|
||||
isSettingTextFromJS = true
|
||||
maybeSetText(reactTextUpdate)
|
||||
isSettingTextFromJS = false
|
||||
}
|
||||
|
||||
public fun maybeSetTextFromState(reactTextUpdate: ReactTextUpdate) {
|
||||
internal fun maybeSetTextFromState(reactTextUpdate: ReactTextUpdate) {
|
||||
isSettingTextFromState = true
|
||||
maybeSetText(reactTextUpdate)
|
||||
isSettingTextFromState = false
|
||||
@@ -679,9 +676,6 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
manageSpans(spannableStringBuilder)
|
||||
stripStyleEquivalentSpans(spannableStringBuilder)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
containsImages = reactTextUpdate.containsImages()
|
||||
|
||||
// When we update text, we trigger onChangeText code that will
|
||||
// try to update state if the wrapper is available. Temporarily disable
|
||||
// to prevent an (asynchronous) infinite loop.
|
||||
@@ -921,54 +915,6 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
}
|
||||
}
|
||||
|
||||
override fun verifyDrawable(drawable: Drawable): Boolean {
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
if (span.drawable === drawable) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.verifyDrawable(drawable)
|
||||
}
|
||||
|
||||
override fun invalidateDrawable(drawable: Drawable) {
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
if (span.drawable === drawable) {
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
super.invalidateDrawable(drawable)
|
||||
}
|
||||
|
||||
public override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
span.onDetachedFromWindow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTemporaryDetach() {
|
||||
super.onStartTemporaryDetach()
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
span.onStartTemporaryDetach()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
|
||||
@@ -994,14 +940,6 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
// Restore the selection since `setTextIsSelectable` changed it.
|
||||
maybeSetSelection(selectionStart, selectionEnd)
|
||||
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
span.onAttachedToWindow()
|
||||
}
|
||||
}
|
||||
|
||||
if (autoFocus && !didAttachToWindow) {
|
||||
requestFocusProgrammatically()
|
||||
}
|
||||
@@ -1009,17 +947,6 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
|
||||
didAttachToWindow = true
|
||||
}
|
||||
|
||||
override fun onFinishTemporaryDetach() {
|
||||
super.onFinishTemporaryDetach()
|
||||
if (containsImages) {
|
||||
val text: Spanned? = text
|
||||
val spans = checkNotNull(text).getSpans(0, text.length, TextInlineImageSpan::class.java)
|
||||
for (span in spans) {
|
||||
span.onFinishTemporaryDetach()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBackgroundColor(color: Int) {
|
||||
setBackgroundColor(this, color)
|
||||
}
|
||||
|
||||
-31
@@ -73,7 +73,6 @@ import com.facebook.react.views.text.ReactTextViewManagerCallback
|
||||
import com.facebook.react.views.text.ReactTypefaceUtils.parseFontVariant
|
||||
import com.facebook.react.views.text.TextAttributeProps
|
||||
import com.facebook.react.views.text.TextLayoutManager
|
||||
import com.facebook.react.views.text.internal.span.TextInlineImageSpan.Companion.possiblyUpdateInlineImageSpans
|
||||
import java.util.LinkedList
|
||||
|
||||
/** Manages instances of TextInput. */
|
||||
@@ -195,11 +194,6 @@ public open class ReactTextInputManager public constructor() :
|
||||
return ReactTextUpdate(
|
||||
sb,
|
||||
mostRecentEventCount,
|
||||
false,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
Gravity.NO_GRAVITY,
|
||||
0,
|
||||
0,
|
||||
@@ -208,31 +202,6 @@ public open class ReactTextInputManager public constructor() :
|
||||
|
||||
override fun updateExtraData(view: ReactEditText, extraData: Any) {
|
||||
if (extraData is ReactTextUpdate) {
|
||||
// TODO T58784068: delete this block of code, these are always unset in Fabric
|
||||
val paddingLeft = extraData.paddingLeft.toInt()
|
||||
val paddingTop = extraData.paddingTop.toInt()
|
||||
val paddingRight = extraData.paddingRight.toInt()
|
||||
val paddingBottom = extraData.paddingBottom.toInt()
|
||||
if (
|
||||
paddingLeft != UNSET ||
|
||||
paddingTop != UNSET ||
|
||||
paddingRight != UNSET ||
|
||||
paddingBottom != UNSET
|
||||
) {
|
||||
view.setPadding(
|
||||
if (paddingLeft != UNSET) paddingLeft else view.paddingLeft,
|
||||
if (paddingTop != UNSET) paddingTop else view.paddingTop,
|
||||
if (paddingRight != UNSET) paddingRight else view.paddingRight,
|
||||
if (paddingBottom != UNSET) paddingBottom else view.paddingBottom,
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
if (extraData.containsImages()) {
|
||||
val spannable = extraData.text
|
||||
possiblyUpdateInlineImageSpans(spannable, view)
|
||||
}
|
||||
|
||||
// Ensure that selection is handled correctly on text update
|
||||
val isCurrentSelectionEmpty = view.selectionStart == view.selectionEnd
|
||||
var selectionStart = UNSET
|
||||
|
||||
Reference in new issue
Block a user