Skip to content

Commit e82a677

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Convert TextLayoutManager to Kotlin and Make Internal (#51966)
Summary: Pull Request resolved: #51966 This starts off mechanically, but needed a couple changes: 1. Some null handling changes to `TextTransform` internals 2. We type MapBuffer keys as `Int` instead of `Short`, because Kotlin does not allow the implicit widening cast that Java does. I also made these internal 3. Some shifts around casting 4. Mark TextLayoutManager internal, and remove usages of `UnstableReactNativeAPI` I verified that there were no usages of the Java side of TextLayoutManager throughout `react-native-libraries`, so marking TextLayoutManager internal is unlikely to break 3p libraries. Changelog: [Android][Breaking] - Make Java Side TextLayoutManager Internal Reviewed By: javache Differential Revision: D76444163 fbshipit-source-id: aabb1c498c731598559f0df5c12e0ecdc266339f
1 parent 42ca46b commit e82a677

File tree

7 files changed

+1048
-1078
lines changed

7 files changed

+1048
-1078
lines changed

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6447,37 +6447,6 @@ public final class com/facebook/react/views/text/TextAttributes {
64476447
public fun toString ()Ljava/lang/String;
64486448
}
64496449

6450-
public class com/facebook/react/views/text/TextLayoutManager {
6451-
public static final field AS_KEY_BASE_ATTRIBUTES S
6452-
public static final field AS_KEY_CACHE_ID S
6453-
public static final field AS_KEY_FRAGMENTS S
6454-
public static final field AS_KEY_HASH S
6455-
public static final field AS_KEY_STRING S
6456-
public static final field FR_KEY_HEIGHT S
6457-
public static final field FR_KEY_IS_ATTACHMENT S
6458-
public static final field FR_KEY_REACT_TAG S
6459-
public static final field FR_KEY_STRING S
6460-
public static final field FR_KEY_TEXT_ATTRIBUTES S
6461-
public static final field FR_KEY_WIDTH S
6462-
public static final field PA_KEY_ADJUST_FONT_SIZE_TO_FIT S
6463-
public static final field PA_KEY_ELLIPSIZE_MODE S
6464-
public static final field PA_KEY_HYPHENATION_FREQUENCY S
6465-
public static final field PA_KEY_INCLUDE_FONT_PADDING S
6466-
public static final field PA_KEY_MAXIMUM_FONT_SIZE S
6467-
public static final field PA_KEY_MAX_NUMBER_OF_LINES S
6468-
public static final field PA_KEY_MINIMUM_FONT_SIZE S
6469-
public static final field PA_KEY_TEXT_ALIGN_VERTICAL S
6470-
public static final field PA_KEY_TEXT_BREAK_STRATEGY S
6471-
public fun <init> ()V
6472-
public static fun deleteCachedSpannableForTag (I)V
6473-
public static fun getOrCreateSpannableForText (Landroid/content/Context;Lcom/facebook/react/common/mapbuffer/MapBuffer;Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)Landroid/text/Spannable;
6474-
public static fun getTextGravity (Lcom/facebook/react/common/mapbuffer/MapBuffer;Landroid/text/Spannable;I)I
6475-
public static fun isRTL (Lcom/facebook/react/common/mapbuffer/MapBuffer;)Z
6476-
public static fun measureLines (Landroid/content/Context;Lcom/facebook/react/common/mapbuffer/MapBuffer;Lcom/facebook/react/common/mapbuffer/MapBuffer;FF)Lcom/facebook/react/bridge/WritableArray;
6477-
public static fun measureText (Landroid/content/Context;Lcom/facebook/react/common/mapbuffer/MapBuffer;Lcom/facebook/react/common/mapbuffer/MapBuffer;FLcom/facebook/yoga/YogaMeasureMode;FLcom/facebook/yoga/YogaMeasureMode;Lcom/facebook/react/views/text/ReactTextViewManagerCallback;[F)J
6478-
public static fun setCachedSpannableForTag (ILandroid/text/Spannable;)V
6479-
}
6480-
64816450
public abstract interface class com/facebook/react/views/textinput/ContentSizeWatcher {
64826451
public abstract fun onLayout ()V
64836452
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private static void buildSpannedFromShadowNode(
110110
if (child instanceof ReactRawTextShadowNode) {
111111
String childText = ((ReactRawTextShadowNode) child).getText();
112112
if (childText != null) {
113-
sb.append(TextTransform.applyNonNull(childText, textAttributes.textTransform));
113+
sb.append(TextTransform.apply(childText, textAttributes.textTransform));
114114
}
115115
} else if (child instanceof ReactBaseTextShadowNode) {
116116
buildSpannedFromShadowNode(
@@ -265,7 +265,7 @@ protected Spannable spannedFromShadowNode(
265265
if (text != null) {
266266
// Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on
267267
// TextInput).
268-
sb.append(TextTransform.applyNonNull(text, textShadowNode.mTextAttributes.textTransform));
268+
sb.append(TextTransform.apply(text, textShadowNode.mTextAttributes.textTransform));
269269
}
270270

271271
buildSpannedFromShadowNode(textShadowNode, sb, ops, null, supportsInlineViews, inlineViews, 0);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,20 @@ public constructor(
134134
view.setSpanned(spanned)
135135

136136
val minimumFontSize: Float =
137-
paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SIZE.toInt()).toFloat()
137+
paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SIZE).toFloat()
138138
view.setMinimumFontSize(minimumFontSize)
139139

140140
val textBreakStrategy =
141141
TextAttributeProps.getTextBreakStrategy(
142-
paragraphAttributes.getString(TextLayoutManager.PA_KEY_TEXT_BREAK_STRATEGY.toInt()))
142+
paragraphAttributes.getString(TextLayoutManager.PA_KEY_TEXT_BREAK_STRATEGY))
143143
val currentJustificationMode =
144144
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) 0 else view.getJustificationMode()
145145

146146
return ReactTextUpdate(
147147
spanned,
148148
-1, // UNUSED FOR TEXT
149149
false, // TODO add this into local Data
150-
TextLayoutManager.getTextGravity(attributedString, spanned, view.gravityHorizontal),
150+
TextLayoutManager.getTextGravity(attributedString, spanned),
151151
textBreakStrategy,
152152
TextAttributeProps.getJustificationMode(props, currentJustificationMode))
153153
}

0 commit comments

Comments
 (0)