Skip to content

Commit

Permalink
Remove support for Android API < 23 in TextLayoutManagerMapBuffer (#3…
Browse files Browse the repository at this point in the history
…9677)

Summary:
Pull Request resolved: #39677

Since minsdk version was increased to 23, we are deleting code using Android APIs < 23 for class TextLayoutManagerMapBuffer

bypass-github-export-checks

changelog: [Android][Breaking] Remove support for Android API < 23 in TextLayoutManagerMapBuffer

Reviewed By: NickGerleman

Differential Revision: D48545518

fbshipit-source-id: fe64730c40ddf42aab0a7f5a19e51eecea4c4bcd
  • Loading branch information
mdvacca authored and facebook-github-bot committed Sep 29, 2023
1 parent 4a563f3 commit c35dcb3
Showing 1 changed file with 21 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,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;
Expand All @@ -341,32 +329,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;
}
Expand Down Expand Up @@ -445,7 +420,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 (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
calculatedWidth = (float) Math.ceil(calculatedWidth);
}

Expand Down

0 comments on commit c35dcb3

Please sign in to comment.