Skip to content

Commit d631ec9

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Migrate ReactTextViewManager to Kotlin (#51721)
Summary: Migrate com.facebook.react.views.text.ReactTextViewManager to Kotlin. In this diff, `ReactTextAnchorViewManager` is made public again as it's extended by `ReactTextViewManager`. ## Changelog: [INTERNAL] - Migrate com.facebook.react.views.text.ReactTextViewManager to Kotlin Pull Request resolved: #51721 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: mdvacca Differential Revision: D75829457 Pulled By: NickGerleman fbshipit-source-id: 425e9ec14f17de5470677b73d68873647bf28675
1 parent 1a335b3 commit d631ec9

4 files changed

Lines changed: 215 additions & 247 deletions

File tree

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6319,33 +6319,35 @@ public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/wi
63196319
protected fun verifyDrawable (Landroid/graphics/drawable/Drawable;)Z
63206320
}
63216321

6322-
public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/react/uimanager/IViewManagerWithChildren, com/facebook/react/views/text/ReactTextViewManagerCallback {
6323-
protected field mReactTextViewManagerCallback Lcom/facebook/react/views/text/ReactTextViewManagerCallback;
6322+
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 {
6323+
public static final field Companion Lcom/facebook/react/views/text/ReactTextViewManager$Companion;
6324+
public static final field REACT_CLASS Ljava/lang/String;
63246325
public fun <init> ()V
63256326
public fun <init> (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)V
6327+
public synthetic fun <init> (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
63266328
public synthetic fun createShadowNodeInstance ()Lcom/facebook/react/uimanager/ReactShadowNode;
63276329
public fun createShadowNodeInstance ()Lcom/facebook/react/views/text/ReactTextShadowNode;
6328-
public fun createShadowNodeInstance (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)Lcom/facebook/react/views/text/ReactTextShadowNode;
6330+
public final fun createShadowNodeInstance (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)Lcom/facebook/react/views/text/ReactTextShadowNode;
63296331
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
63306332
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/text/ReactTextView;
63316333
public fun getExportedCustomDirectEventTypeConstants ()Ljava/util/Map;
63326334
public fun getName ()Ljava/lang/String;
63336335
public fun getShadowNodeClass ()Ljava/lang/Class;
63346336
public fun needsCustomLayoutForChildren ()Z
6335-
protected synthetic fun onAfterUpdateTransaction (Landroid/view/View;)V
6336-
protected fun onAfterUpdateTransaction (Lcom/facebook/react/views/text/ReactTextView;)V
6337+
public synthetic fun onAfterUpdateTransaction (Landroid/view/View;)V
63376338
public fun onPostProcessSpannable (Landroid/text/Spannable;)V
6338-
protected synthetic fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View;
6339-
protected fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/views/text/ReactTextView;)Lcom/facebook/react/views/text/ReactTextView;
6340-
public fun setOverflow (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/String;)V
6339+
public synthetic fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View;
6340+
public final fun setOverflow (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/String;)V
63416341
public synthetic fun setPadding (Landroid/view/View;IIII)V
63426342
public fun setPadding (Lcom/facebook/react/views/text/ReactTextView;IIII)V
63436343
public synthetic fun updateExtraData (Landroid/view/View;Ljava/lang/Object;)V
63446344
public fun updateExtraData (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/Object;)V
63456345
public synthetic fun updateState (Landroid/view/View;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object;
63466346
public fun updateState (Lcom/facebook/react/views/text/ReactTextView;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object;
6347-
protected synthetic fun updateViewAccessibility (Landroid/view/View;)V
6348-
protected fun updateViewAccessibility (Lcom/facebook/react/views/text/ReactTextView;)V
6347+
public synthetic fun updateViewAccessibility (Landroid/view/View;)V
6348+
}
6349+
6350+
public final class com/facebook/react/views/text/ReactTextViewManager$Companion {
63496351
}
63506352

63516353
public abstract interface class com/facebook/react/views/text/ReactTextViewManagerCallback {

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.text.util.Linkify
1313
import android.view.Gravity
1414
import com.facebook.common.logging.FLog
1515
import com.facebook.react.common.ReactConstants
16+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1617
import com.facebook.react.uimanager.BackgroundStyleApplicator
1718
import com.facebook.react.uimanager.BaseViewManager
1819
import com.facebook.react.uimanager.LengthPercentage
@@ -31,26 +32,27 @@ import com.facebook.react.views.text.DefaultStyleValuesUtil.getDefaultTextColorH
3132
*
3233
* This is a "shadowing" view manager, which means that the
3334
* [com.facebook.react.uimanager.NativeViewHierarchyManager] will NOT manage children of native
34-
* [android.widget.TextView] instances instantiated by this manager. Instead we use @{link
35-
* ReactBaseTextShadowNode} hierarchy to calculate a [android.text.Spannable] text represented the
35+
* [android.widget.TextView] instances instantiated by this manager. Instead we use
36+
* [ReactBaseTextShadowNode] hierarchy to calculate a [android.text.Spannable] text represented the
3637
* whole text subtree.
3738
*/
38-
internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?> :
39+
@UnstableReactNativeAPI
40+
public abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?> :
3941
BaseViewManager<ReactTextView, C>() {
4042

4143
@ReactProp(name = "accessible")
42-
public fun setAccessible(view: ReactTextView, accessible: Boolean) {
44+
internal fun setAccessible(view: ReactTextView, accessible: Boolean) {
4345
view.isFocusable = accessible
4446
}
4547

4648
// maxLines can only be set in master view (block), doesn't really make sense to set in a span
4749
@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = ViewDefaults.NUMBER_OF_LINES)
48-
public fun setNumberOfLines(view: ReactTextView, numberOfLines: Int) {
50+
internal fun setNumberOfLines(view: ReactTextView, numberOfLines: Int) {
4951
view.setNumberOfLines(numberOfLines)
5052
}
5153

5254
@ReactProp(name = ViewProps.ELLIPSIZE_MODE)
53-
public fun setEllipsizeMode(view: ReactTextView, ellipsizeMode: String?) {
55+
internal fun setEllipsizeMode(view: ReactTextView, ellipsizeMode: String?) {
5456
when (ellipsizeMode) {
5557
null,
5658
"tail" -> view.setEllipsizeLocation(TextUtils.TruncateAt.END)
@@ -65,22 +67,22 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
6567
}
6668

6769
@ReactProp(name = ViewProps.ADJUSTS_FONT_SIZE_TO_FIT)
68-
public fun setAdjustFontSizeToFit(view: ReactTextView, adjustsFontSizeToFit: Boolean) {
70+
internal fun setAdjustFontSizeToFit(view: ReactTextView, adjustsFontSizeToFit: Boolean) {
6971
view.setAdjustFontSizeToFit(adjustsFontSizeToFit)
7072
}
7173

7274
@ReactProp(name = ViewProps.FONT_SIZE)
73-
public fun setFontSize(view: ReactTextView, fontSize: Float) {
75+
internal fun setFontSize(view: ReactTextView, fontSize: Float) {
7476
view.setFontSize(fontSize)
7577
}
7678

7779
@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = 0f)
78-
public fun setLetterSpacing(view: ReactTextView, letterSpacing: Float) {
80+
internal fun setLetterSpacing(view: ReactTextView, letterSpacing: Float) {
7981
view.letterSpacing = letterSpacing
8082
}
8183

8284
@ReactProp(name = ViewProps.TEXT_ALIGN_VERTICAL)
83-
public fun setTextAlignVertical(view: ReactTextView, textAlignVertical: String?) {
85+
internal fun setTextAlignVertical(view: ReactTextView, textAlignVertical: String?) {
8486
when (textAlignVertical) {
8587
null,
8688
"auto" -> view.setGravityVertical(Gravity.NO_GRAVITY)
@@ -95,17 +97,17 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
9597
}
9698

9799
@ReactProp(name = "selectable")
98-
public fun setSelectable(view: ReactTextView, isSelectable: Boolean) {
100+
internal fun setSelectable(view: ReactTextView, isSelectable: Boolean) {
99101
view.setTextIsSelectable(isSelectable)
100102
}
101103

102104
@ReactProp(name = "selectionColor", customType = "Color")
103-
public fun setSelectionColor(view: ReactTextView, color: Int?) {
105+
internal fun setSelectionColor(view: ReactTextView, color: Int?) {
104106
view.highlightColor = color ?: getDefaultTextColorHighlight(view.context)
105107
}
106108

107109
@ReactProp(name = "android_hyphenationFrequency")
108-
public fun setAndroidHyphenationFrequency(view: ReactTextView, frequency: String?) {
110+
internal fun setAndroidHyphenationFrequency(view: ReactTextView, frequency: String?) {
109111
when (frequency) {
110112
null,
111113
"none" -> view.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
@@ -127,7 +129,7 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
127129
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
128130
ViewProps.BORDER_BOTTOM_LEFT_RADIUS],
129131
defaultFloat = Float.NaN)
130-
public fun setBorderRadius(view: ReactTextView, index: Int, borderRadius: Float) {
132+
internal fun setBorderRadius(view: ReactTextView, index: Int, borderRadius: Float) {
131133
val radius =
132134
if (borderRadius.isNaN()) {
133135
null
@@ -138,7 +140,7 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
138140
}
139141

140142
@ReactProp(name = "borderStyle")
141-
public fun setBorderStyle(view: ReactTextView, borderStyle: String?) {
143+
internal fun setBorderStyle(view: ReactTextView, borderStyle: String?) {
142144
val parsedBorderStyle = if (borderStyle == null) null else fromString(borderStyle)
143145
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle)
144146
}
@@ -154,7 +156,7 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
154156
ViewProps.BORDER_START_WIDTH,
155157
ViewProps.BORDER_END_WIDTH],
156158
defaultFloat = Float.NaN)
157-
public fun setBorderWidth(view: ReactTextView, index: Int, width: Float) {
159+
internal fun setBorderWidth(view: ReactTextView, index: Int, width: Float) {
158160
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width)
159161
}
160162

@@ -167,22 +169,22 @@ internal abstract class ReactTextAnchorViewManager<C : ReactBaseTextShadowNode?>
167169
"borderTopColor",
168170
"borderBottomColor"],
169171
customType = "Color")
170-
public fun setBorderColor(view: ReactTextView, index: Int, color: Int?) {
172+
internal fun setBorderColor(view: ReactTextView, index: Int, color: Int?) {
171173
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.values()[index], color)
172174
}
173175

174176
@ReactProp(name = ViewProps.INCLUDE_FONT_PADDING, defaultBoolean = true)
175-
public fun setIncludeFontPadding(view: ReactTextView, includepad: Boolean) {
177+
internal fun setIncludeFontPadding(view: ReactTextView, includepad: Boolean) {
176178
view.includeFontPadding = includepad
177179
}
178180

179181
@ReactProp(name = "disabled", defaultBoolean = false)
180-
public fun setDisabled(view: ReactTextView, disabled: Boolean) {
182+
internal fun setDisabled(view: ReactTextView, disabled: Boolean) {
181183
view.isEnabled = !disabled
182184
}
183185

184186
@ReactProp(name = "dataDetectorType")
185-
public fun setDataDetectorType(view: ReactTextView, type: String?) {
187+
internal fun setDataDetectorType(view: ReactTextView, type: String?) {
186188
when (type) {
187189
"phoneNumber" -> {
188190
view.setLinkifyMask(Linkify.PHONE_NUMBERS)

0 commit comments

Comments
 (0)