Hello here! I'm playing with `Text` composable, th...
# compose
g
Hello here! I'm playing with
Text
composable, the callback
onTextLayout
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!
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.
However, I'm interested to know why states updated inside my
onTextLayout
don't force a recomposition. 🤔
a
if it's only being read by the drawBehind I would expect it to trigger a draw but not a recomposition