Skip to content

Commit

Permalink
Auto set ellipsize if maxLines are specified without an accompanying …
Browse files Browse the repository at this point in the history
…ellipsize

Summary: On recent versions of Android `Layout.getHeight()` doesn't consider maxLines unless an ellipsize method is specified. This ensures consistent behavior expected from `maxLines` across API levels by auto-defaulting to end if `maxLines` is specified but `ellipsize` is not

Reviewed By: muraziz

Differential Revision: D16610143

fbshipit-source-id: 76ada157407407434716d61c15028bd1e19fe463
  • Loading branch information
xiphirx authored and facebook-github-bot committed Aug 2, 2019
1 parent 3308ee8 commit 3bef059
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,19 @@ private static Layout createTextLayout(
throw new IllegalStateException("Unexpected size mode: " + SizeSpec.getMode(widthSpec));
}

final TruncateAt actualEllipsize;
if (ellipsize == null && maxLines != Integer.MAX_VALUE) {
// On recent apis (> 24) max lines is no longer considered for calculating layout height if an
// ellipsize method isn't specified. To keep consistent behavior across platforms we default
// to end if you specify maxLines but not ellipsize.
actualEllipsize = TruncateAt.END;
} else {
actualEllipsize = ellipsize;
}

layoutBuilder
.setDensity(density)
.setEllipsize(ellipsize)
.setEllipsize(actualEllipsize)
.setMaxLines(maxLines)
.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor)
.setSingleLine(isSingleLine)
Expand Down

0 comments on commit 3bef059

Please sign in to comment.