Skip to content

Commit 07e8852

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Remove support for Android API < 23 in ReactTextShadowNode (#39675)
Summary: Pull Request resolved: #39675 Since minsdk version was increased to 23, we are deleting code using Android APIs < 23 for class ReactTextShadowNode bypass-github-export-checks changelog: [Android][Breaking] Remove support for Android API < 23 in ReactTextShadowNode Reviewed By: NickGerleman Differential Revision: D48545511 fbshipit-source-id: c0462ee72746be73bb3acdf0c2336353e65da57a
1 parent 63884b4 commit 07e8852

File tree

1 file changed

+33
-47
lines changed

1 file changed

+33
-47
lines changed

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

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

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

10-
import android.annotation.TargetApi;
1110
import android.os.Build;
1211
import android.text.BoringLayout;
1312
import android.text.Layout;
@@ -47,7 +46,6 @@
4746
* <p>The class measures text in {@code <Text>} view and feeds native {@link TextView} using {@code
4847
* Spannable} object constructed in superclass.
4948
*/
50-
@TargetApi(Build.VERSION_CODES.M)
5149
public class ReactTextShadowNode extends ReactBaseTextShadowNode {
5250

5351
// It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it
@@ -148,7 +146,7 @@ public long measure(
148146
}
149147
}
150148

151-
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) {
149+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
152150
layoutWidth = (float) Math.ceil(layoutWidth);
153151
}
154152
float layoutHeight = height;
@@ -222,28 +220,22 @@ private Layout measureSpannedText(Spannable text, float width, YogaMeasureMode w
222220
|| (!YogaConstants.isUndefined(desiredWidth) && desiredWidth <= width))) {
223221
// Is used when the width is not known and the text is not boring, ie. if it contains
224222
// unicode characters.
225-
226223
int hintWidth = (int) Math.ceil(desiredWidth);
227-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
228-
layout =
229-
new StaticLayout(text, textPaint, hintWidth, alignment, 1.f, 0.f, mIncludeFontPadding);
230-
} else {
231-
StaticLayout.Builder builder =
232-
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, hintWidth)
233-
.setAlignment(alignment)
234-
.setLineSpacing(0.f, 1.f)
235-
.setIncludePad(mIncludeFontPadding)
236-
.setBreakStrategy(mTextBreakStrategy)
237-
.setHyphenationFrequency(mHyphenationFrequency);
238-
239-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
240-
builder.setJustificationMode(mJustificationMode);
241-
}
242-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
243-
builder.setUseLineSpacingFromFallbacks(true);
244-
}
245-
layout = builder.build();
224+
StaticLayout.Builder builder =
225+
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, hintWidth)
226+
.setAlignment(alignment)
227+
.setLineSpacing(0.f, 1.f)
228+
.setIncludePad(mIncludeFontPadding)
229+
.setBreakStrategy(mTextBreakStrategy)
230+
.setHyphenationFrequency(mHyphenationFrequency);
231+
232+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
233+
builder.setJustificationMode(mJustificationMode);
234+
}
235+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
236+
builder.setUseLineSpacingFromFallbacks(true);
246237
}
238+
layout = builder.build();
247239

248240
} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
249241
// Is used for single-line, boring text when the width is either unknown or bigger
@@ -260,32 +252,25 @@ private Layout measureSpannedText(Spannable text, float width, YogaMeasureMode w
260252
mIncludeFontPadding);
261253
} else {
262254
// Is used for multiline, boring text and the width is known.
255+
// Android 11+ introduces changes in text width calculation which leads to cases
256+
// where the container is measured smaller than text. Math.ceil prevents it
257+
// See T136756103 for investigation
258+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
259+
width = (float) Math.ceil(width);
260+
}
263261

264-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
265-
layout =
266-
new StaticLayout(
267-
text, textPaint, (int) width, alignment, 1.f, 0.f, mIncludeFontPadding);
268-
} else {
269-
// Android 11+ introduces changes in text width calculation which leads to cases
270-
// where the container is measured smaller than text. Math.ceil prevents it
271-
// See T136756103 for investigation
272-
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) {
273-
width = (float) Math.ceil(width);
274-
}
275-
276-
StaticLayout.Builder builder =
277-
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, (int) width)
278-
.setAlignment(alignment)
279-
.setLineSpacing(0.f, 1.f)
280-
.setIncludePad(mIncludeFontPadding)
281-
.setBreakStrategy(mTextBreakStrategy)
282-
.setHyphenationFrequency(mHyphenationFrequency);
262+
StaticLayout.Builder builder =
263+
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, (int) width)
264+
.setAlignment(alignment)
265+
.setLineSpacing(0.f, 1.f)
266+
.setIncludePad(mIncludeFontPadding)
267+
.setBreakStrategy(mTextBreakStrategy)
268+
.setHyphenationFrequency(mHyphenationFrequency);
283269

284-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
285-
builder.setUseLineSpacingFromFallbacks(true);
286-
}
287-
layout = builder.build();
270+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
271+
builder.setUseLineSpacingFromFallbacks(true);
288272
}
273+
layout = builder.build();
289274
}
290275
return layout;
291276
}
@@ -361,6 +346,7 @@ public void setShouldNotifyOnTextLayout(boolean shouldNotifyOnTextLayout) {
361346
}
362347

363348
@Override
349+
@Nullable
364350
public Iterable<? extends ReactShadowNode> calculateLayoutOnChildren() {
365351
// Run flexbox on and return the descendants which are inline views.
366352

@@ -374,7 +360,7 @@ public Iterable<? extends ReactShadowNode> calculateLayoutOnChildren() {
374360
"Spannable element has not been prepared in onBeforeLayout");
375361
TextInlineViewPlaceholderSpan[] placeholders =
376362
text.getSpans(0, text.length(), TextInlineViewPlaceholderSpan.class);
377-
ArrayList<ReactShadowNode> shadowNodes = new ArrayList<ReactShadowNode>(placeholders.length);
363+
ArrayList<ReactShadowNode> shadowNodes = new ArrayList<>(placeholders.length);
378364

379365
for (TextInlineViewPlaceholderSpan placeholder : placeholders) {
380366
ReactShadowNode child = mInlineViews.get(placeholder.getReactTag());

0 commit comments

Comments
 (0)