https://kotlinlang.org logo
#compose
Title
# compose
s

samuel

07/31/2022, 1:10 PM
I would like to get the index of the last visible line in case the text in my
Text
composable overflows. I came across
TextLayoutResult.getLineEnd
that seems like it could help me in this case. However, i need to supply the
lineIndex
. How would i go about getting the
lineIndex
of the line that is overflowing?
Copy code
Text(
    text = "my text",
    modifier = Modifier.fillMaxWidth(),
    overflow = TextOverflow.Ellipsis,
    onTextLayout = { textLayoutResult ->
        if (textLayoutResult.didOverflowHeight || textLayoutResult.didOverflowWidth) {
            val overFlowingLineIndex = textLayoutResult.getLineEnd(
// Using the first line here, but i would like to compute the the line index of the overflow
                lineIndex = 0, 
                visibleEnd = true
            )
        }
    },
)
Since currently there is only ellipsize end; it should be the lineCount-1
s

samuel

07/31/2022, 6:42 PM
Ah yes!
lineCount-1
is exactly what i needed, thank you 😄
15 Views