Skip to content

Commit

Permalink
Text measurement, Math.ceil calculatedWidth
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] - Fix incorrect text container measurement for Android 11+

Reviewed By: mdvacca

Differential Revision: D41559873

fbshipit-source-id: 76c200693cd10b9b7fe883dd81b0c3c1dbdecf27
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Nov 28, 2022
1 parent 6c33fd1 commit 8b00b4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ 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) {
calculatedWidth = (float) Math.ceil(calculatedWidth);
}

float calculatedHeight = height;
if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) {
calculatedHeight = layout.getLineBottom(calculatedLineCount - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ 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) {
calculatedWidth = (float) Math.ceil(calculatedWidth);
}

float calculatedHeight = height;
if (heightYogaMeasureMode != YogaMeasureMode.EXACTLY) {
calculatedHeight = layout.getLineBottom(calculatedLineCount - 1);
Expand Down

0 comments on commit 8b00b4f

Please sign in to comment.