From 4a563f30d2de89eee1459d8ee79c9ac042a86a96 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 29 Sep 2023 12:11:24 -0700 Subject: [PATCH] Remove support for Android API < 23 in TextLayoutManager (#39679) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../react/views/text/TextLayoutManager.java | 67 ++++++------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index ffd5b2f1a5c4c2..93eda5d06b3866 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -258,26 +258,14 @@ private static Layout createLayout( // unicode characters. int hintWidth = (int) Math.ceil(desiredWidth); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - layout = - new StaticLayout( - text, - sTextPaintInstance, - hintWidth, - Layout.Alignment.ALIGN_NORMAL, - 1.f, - 0.f, - includeFontPadding); - } else { - layout = - StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, hintWidth) - .setAlignment(Layout.Alignment.ALIGN_NORMAL) - .setLineSpacing(0.f, 1.f) - .setIncludePad(includeFontPadding) - .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(hyphenationFrequency) - .build(); - } + layout = + StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, hintWidth) + .setAlignment(Layout.Alignment.ALIGN_NORMAL) + .setLineSpacing(0.f, 1.f) + .setIncludePad(includeFontPadding) + .setBreakStrategy(textBreakStrategy) + .setHyphenationFrequency(hyphenationFrequency) + .build(); } else if (boring != null && (unconstrainedWidth || boring.width <= width)) { int boringLayoutWidth = boring.width; if (boring.width < 0) { @@ -300,32 +288,19 @@ private static Layout createLayout( includeFontPadding); } else { // Is used for multiline, boring text and the width is known. - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - layout = - new StaticLayout( - text, - sTextPaintInstance, - (int) width, - Layout.Alignment.ALIGN_NORMAL, - 1.f, - 0.f, - includeFontPadding); - } else { - StaticLayout.Builder builder = - StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, (int) width) - .setAlignment(Layout.Alignment.ALIGN_NORMAL) - .setLineSpacing(0.f, 1.f) - .setIncludePad(includeFontPadding) - .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(hyphenationFrequency); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - builder.setUseLineSpacingFromFallbacks(true); - } - - layout = builder.build(); + StaticLayout.Builder builder = + StaticLayout.Builder.obtain(text, 0, spanLength, sTextPaintInstance, (int) width) + .setAlignment(Layout.Alignment.ALIGN_NORMAL) + .setLineSpacing(0.f, 1.f) + .setIncludePad(includeFontPadding) + .setBreakStrategy(textBreakStrategy) + .setHyphenationFrequency(hyphenationFrequency); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + builder.setUseLineSpacingFromFallbacks(true); } + + layout = builder.build(); } return layout; } @@ -423,7 +398,7 @@ public static long measureText( // Android 11+ introduces changes in text width calculation which leads to cases // where the container is measured smaller than text. Math.ceil prevents it // See T136756103 for investigation - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { calculatedWidth = (float) Math.ceil(calculatedWidth); }