Hello! Is there any way to get the overflow string...
# compose
z
Hello! Is there any way to get the overflow string when using
Text()
? I am writing a text reader that flips pages left and right. It needs to fill the first page with text, then fill the second page with the remaining text, then fill the third page with the remaining text, and so on.
r
look at
onTextLayout = { it.hasVisualOverflow }
z
@Raphael TEYSSANDIER This variable seems to only know whether it overflows, but cannot get the overflow text…
r
there is bunch of method from
TextLayoutResult
, that help you with what you want
z
You could also use TextMeasurer to break the text yourself
z
The following code works 😴
Copy code
Text(
    text = sampleText,
    onTextLayout = { textLayoutResult ->
        with(textLayoutResult) {
            val lastLine = getLineForVerticalPosition(size.height.toFloat())
            val lineEnd = getLineEnd(lastLine)
            remaingText = sampleText.substring(lineEnd)
        }
    }
}