Skip to content

Commit

Permalink
Fix issue where text would truncate sometimes
Browse files Browse the repository at this point in the history
Summary:
TextView will set `setUseLineSpacingFromFallbacks` to `true` for their `StaticLayout`s while we ignore it in this case (`false` default). The docs even recommend setting it to `true`: https://developer.android.com/reference/android/text/StaticLayout.Builder#setUseLineSpacingFromFallbacks(boolean)

We set this in the `StaticLayout` builder below, but not up here so lets do that.

Changelog: [Internal]

Differential Revision: D65171352
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 29, 2024
1 parent cc6f75b commit f309f90
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,21 @@ private static Layout createLayout(
}

int hintWidth = (int) Math.ceil(desiredWidth);
layout =
StaticLayout.Builder builder =
StaticLayout.Builder.obtain(text, 0, spanLength, paint, hintWidth)
.setAlignment(alignment)
.setLineSpacing(0.f, 1.f)
.setIncludePad(includeFontPadding)
.setBreakStrategy(textBreakStrategy)
.setHyphenationFrequency(hyphenationFrequency)
.setTextDirection(
isScriptRTL ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR)
.build();
isScriptRTL ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setUseLineSpacingFromFallbacks(true);
}

layout = builder.build();

} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
int boringLayoutWidth = boring.width;
Expand Down

0 comments on commit f309f90

Please sign in to comment.