to get information about text measurements and the modifier
drawBehind
.
Copy code
Text(
text = "My text here\n Multi line",
modifier = Modifier.drawBehind {
// Draw something here
},
onTextLayout = { textLayoutResult ->
// Get value of textLayoutResult.multiParagraph.lineCount
// Get values of textLayoutResult.multiParagraph.getLineHeight(index)
}
)
If I'm using this snippet with two states, it works well but my composable is draw 2 times. First time to measure the text and the second time when my states are updated inside the
onTextLayout
callback which force a new recomposition.
I would like to know if it is possible to avoid to draw 2 times my text when there are no changes between my first and second composition?
If anyone have an idea, I'm very interested!
Thanks!
gpaligot
09/16/2021, 8:53 PM
Oh ok, it seems that it isn't states updated in
onTextLayout
that force the recomposition. I simplified my composable and it is another states which is responsible about this recomposition.
gpaligot
09/16/2021, 8:54 PM
However, I'm interested to know why states updated inside my
onTextLayout
don't force a recomposition. 🤔
a
Adam Powell
09/16/2021, 11:12 PM
if it's only being read by the drawBehind I would expect it to trigger a draw but not a recomposition