gpaligot
09/16/2021, 8:34 PMText
composable, the callback onTextLayout
to get information about text measurements and the modifier drawBehind
.
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 PMonTextLayout
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 PMonTextLayout
don't force a recomposition. 🤔Adam Powell
09/16/2021, 11:12 PM