In this snippet, why does the print maxWidth in th...
# compose
h
In this snippet, why does the print maxWidth in the detectTapGestures get closured and doesnt update when the box recomposes upon resizing?
Copy code
BoxWithConstraints {
        println("Box recomposed width: $maxWidth")
        Column(
            modifier
                .pointerInput(Unit) {
                    detectTapGestures { println("Current box width: $maxWidth") }
                }
        ) { }
    }
e.g. if i resize it and then click on the box, it still shows the old width even though it has recomposed.
Copy code
Box recomposed width: 568.8.dp      <- original width
Box recomposed width: 1515.2.dp     <- resized width
Current box width: 568.8.dp         <- printing width on tap still prints old width even after resizing occurred
I'd have thought the column and its modifier would be recomposed from scratch with the updated maxWidth when the Box is recomposed. how can i make it so the maxWidth printed on tap gesture is updated upon the box being recomposed?
b
pointerInput has a size property btw, so you might be able to avoid this altogether?
☝️ 1
👍 1
a
Because the block of
Modifier.pointerInput
is long-running and won't restart on recomposition automatically, so it only captures the initial value. Read its document for more details.
h
thanks!
d
Anyways, if you want to force a restart you can always pass the dependent param as key.