Skip to content

Commit 4a563f3

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Remove support for Android API < 23 in TextLayoutManager (#39679)
Summary: Pull Request resolved: #39679 Since minsdk version was increased to 23, we are deleting code using Android APIs < 23 for class TextLayoutManager bypass-github-export-checks changelog: [Android][Breaking] Remove support for Android API < 23 in TextLayoutManager Reviewed By: NickGerleman Differential Revision: D48545502 fbshipit-source-id: b478013bfaf71264a1009669a10d9e8dfb396802
1 parent 9454587 commit 4a563f3

File tree

1 file changed

+21
-46
lines changed

1 file changed

+21
-46
lines changed

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

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,14 @@ private static Layout createLayout(
258258
// unicode characters.
259259

260260
int hintWidth = (int) Math.ceil(desiredWidth);
261-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
262-
layout =
263-
new StaticLayout(
264-
text,
265-
sTextPaintInstance,
266-
hintWidth,
267-
Layout.Alignment.ALIGN_NORMAL,
268-
1.f,
269-
0.f,
270-
includeFontPadding);
271-
} else {
272-
layout =
273-
StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, hintWidth)
274-
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
275-
.setLineSpacing(0.f, 1.f)
276-
.setIncludePad(includeFontPadding)
277-
.setBreakStrategy(textBreakStrategy)
278-
.setHyphenationFrequency(hyphenationFrequency)
279-
.build();
280-
}
261+
layout =
262+
StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, hintWidth)
263+
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
264+
.setLineSpacing(0.f, 1.f)
265+
.setIncludePad(includeFontPadding)
266+
.setBreakStrategy(textBreakStrategy)
267+
.setHyphenationFrequency(hyphenationFrequency)
268+
.build();
281269
} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
282270
int boringLayoutWidth = boring.width;
283271
if (boring.width < 0) {
@@ -300,32 +288,19 @@ private static Layout createLayout(
300288
includeFontPadding);
301289
} else {
302290
// Is used for multiline, boring text and the width is known.
303-
304-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
305-
layout =
306-
new StaticLayout(
307-
text,
308-
sTextPaintInstance,
309-
(int) width,
310-
Layout.Alignment.ALIGN_NORMAL,
311-
1.f,
312-
0.f,
313-
includeFontPadding);
314-
} else {
315-
StaticLayout.Builder builder =
316-
StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, (int) width)
317-
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
318-
.setLineSpacing(0.f, 1.f)
319-
.setIncludePad(includeFontPadding)
320-
.setBreakStrategy(textBreakStrategy)
321-
.setHyphenationFrequency(hyphenationFrequency);
322-
323-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
324-
builder.setUseLineSpacingFromFallbacks(true);
325-
}
326-
327-
layout = builder.build();
291+
StaticLayout.Builder builder =
292+
StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, (int) width)
293+
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
294+
.setLineSpacing(0.f, 1.f)
295+
.setIncludePad(includeFontPadding)
296+
.setBreakStrategy(textBreakStrategy)
297+
.setHyphenationFrequency(hyphenationFrequency);
298+
299+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
300+
builder.setUseLineSpacingFromFallbacks(true);
328301
}
302+
303+
layout = builder.build();
329304
}
330305
return layout;
331306
}
@@ -423,7 +398,7 @@ public static long measureText(
423398
// Android 11+ introduces changes in text width calculation which leads to cases
424399
// where the container is measured smaller than text. Math.ceil prevents it
425400
// See T136756103 for investigation
426-
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) {
401+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
427402
calculatedWidth = (float) Math.ceil(calculatedWidth);
428403
}
429404

0 commit comments

Comments
 (0)