Alexander Maryanovsky
08/26/2025, 1:14 PMAlexander Maryanovsky
08/26/2025, 1:16 PMBox(Modifier.size(300.dp)) {
if (showBox) {
val parentLayoutBounds = ...
}
}
We currently add an empty layout and attach this to it:
private inline fun Modifier.parentBoundsInWindow(
crossinline onBoundsChanged: (IntRect) -> Unit
) = this.onPlaced { childCoordinates ->
childCoordinates.parentCoordinates?.let {
val layoutPosition = it.positionInWindow().round()
val layoutSize = it.size
onBoundsChanged(IntRect(layoutPosition, layoutSize))
}
}
So:
var parentLayoutBounds: IntRect? by remember { mutableStateOf(null) }
EmptyLayout(Modifier.parentBoundsInWindow { parentLayoutBounds = it })
Alexander Maryanovsky
08/26/2025, 1:17 PMAlexander Maryanovsky
08/26/2025, 1:19 PMparentLayoutBounds
in the compositionLouis Pullen-Freilich [G]
08/26/2025, 2:01 PMAlexander Maryanovsky
08/26/2025, 2:03 PMparentLayoutBounds
to be a MutableState
and passed that to the measure policy that needs it