Skip to content

Commit

Permalink
Check for minimum font size once
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Apr 15, 2024
1 parent 7c2f944 commit 4451253
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,17 @@ public static void adjustSpannableFontToFit(
BoringLayout.Metrics boring = BoringLayout.isBoring(text, sTextPaintInstance);
Layout layout = createLayout(text, boring, width, widthYogaMeasureMode, includeFontPadding, textBreakStrategy, hyphenationFrequency);

// Find the largest font size used in the spannable to use as a starting point.
// Minimum font size is 4pts to match the iOS implementation.
int currentFontSize = (int) (Double.isNaN(minimumFontSizeAttr) ? PixelUtil.toPixelFromDIP(4) : minimumFontSizeAttr);
int minimumFontSize = (int) (Double.isNaN(minimumFontSizeAttr) ? PixelUtil.toPixelFromDIP(4) : minimumFontSizeAttr);

// Find the largest font size used in the spannable to use as a starting point.
int currentFontSize = minimumFontSize;
ReactAbsoluteSizeSpan[] spans = text.getSpans(0, text.length(), ReactAbsoluteSizeSpan.class);
for (ReactAbsoluteSizeSpan span : spans) {
currentFontSize = Math.max(currentFontSize, span.getSize());
}

int initialFontSize = currentFontSize;
int minimumFontSize = (int) (Double.isNaN(minimumFontSizeAttr) ? PixelUtil.toPixelFromDIP(4) : minimumFontSizeAttr);
while (currentFontSize > minimumFontSize
&& (maximumNumberOfLines != ReactConstants.UNSET && layout.getLineCount() > maximumNumberOfLines
|| heightYogaMeasureMode != YogaMeasureMode.UNDEFINED && layout.getHeight() > height)) {
Expand Down

0 comments on commit 4451253

Please sign in to comment.