Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,12 @@ internal object TextLayoutManager {
}
}
}
val enableStartOverhang = widthYogaMeasureMode == YogaMeasureMode.EXACTLY
// Bounds-based width is limited to text with RTL characters. An EXACTLY width usually comes
// from an earlier advance-based AT_MOST measurement, and LTR glyph bounds that are wider than
// their advances (some OEM fonts) would make a single line overflow that width and ellipsize.
val enableStartOverhang =
widthYogaMeasureMode == YogaMeasureMode.EXACTLY &&
TextDirectionHeuristics.ANYRTL_LTR.isRtl(text, 0, text.length)
val layout =
buildLayout(
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ class TextLayoutManagerStartOverhangTest {
assertThat(getBooleanLayoutProperty(layout, "getShiftDrawingOffsetForStartOverhang")).isFalse()
}

@Test
@Config(sdk = [35])
fun `EXACTLY mode keeps advance based width measurement for LTR text`() {
val layout =
createLayout(
YogaMeasureMode.EXACTLY,
text = SpannableString("Just listed"),
ellipsizeMode = TextUtils.TruncateAt.END,
maxNumberOfLines = 1,
)

assertThat(getBooleanLayoutProperty(layout, "getUseBoundsForWidth")).isFalse()
assertThat(getBooleanLayoutProperty(layout, "getShiftDrawingOffsetForStartOverhang")).isFalse()
}

@Test
@Config(sdk = [35])
fun `EXACTLY mode enables start overhang support for mixed LTR and RTL text`() {
val layout = createLayout(YogaMeasureMode.EXACTLY, text = SpannableString("Hello שלום"))

assertThat(getBooleanLayoutProperty(layout, "getUseBoundsForWidth")).isTrue()
}

@Test
@Config(sdk = [35])
fun `RTL right overhang is rounded up to reserve whole pixels`() {
Expand Down
Loading