PHondogo
10/23/2023, 8:31 AMAlexander Zhirkevich
10/23/2023, 8:39 AMBoxWithConstraints {
Text(if (constraints.hasBoundedHeight) "Static" else "Scrollable")
}
Zach Klippenstein (he/him) [MOD]
10/23/2023, 4:42 PMBoxWithConstraints
. If the element isn’t composed, that code won’t run at all, and if it is, it’s super inefficient.
• If you’re in a lazy list, use LazyListLayoutInfo.
• If not a lazy list, you can use a DisposableEffect
to keep track of composed items is the simplest way (the effect will start when first composed, and be disposed when removed from composition). If you want to check if an item is visible, use the LayoutCoordinates
of the item to get the clipped bounds.
◦ Depending on when you need to check visibility, you can use onPlaced
(if you only need to check on demand) or onGloballyPositioned
(if you need to check every time the visibility may have changed).Alexander Zhirkevich
10/23/2023, 4:56 PMPHondogo
10/23/2023, 5:00 PMAlexander Zhirkevich
10/23/2023, 5:07 PMZach Klippenstein (he/him) [MOD]
10/23/2023, 5:16 PMlayout { measurable, constraints ->
if (constraints.hasBoundedHeight) { … }
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
placeable.placeRelative(0, 0)
}
}