Tgo1014
08/14/2024, 9:50 AMalpha(0f)
and using the onGloballyPositioned
to get the size. But I’m not sure this is the best optionMR3Y
08/14/2024, 11:49 AMalpha
to 0f
still makes it interactable/visible for a11y services which is probably not what you want here. You can simulate exactly what you say using a custom layout (by measuring the composable but not actually placing it) Take some inspiration from this thread:
https://kotlinlang.slack.com/archives/C04TPPEQKEJ/p1723131281969339?thread_ts=1723127528.109779&cid=C04TPPEQKEJStylianos Gakis
08/14/2024, 11:56 AMTgo1014
08/14/2024, 12:25 PMonPlaced
as suggested by Stylianos and solved it like this so far. I’m open to suggestions to improve it 😅
@Composable
fun MeasureBox(
content: @Composable () -> Unit,
onMeasured: (IntSize) -> Unit,
) {
var isMeasured by remember { mutableStateOf(false) }
if (isMeasured) return
Box(
modifier = Modifier
.alpha(0f)
.onPlaced {
isMeasured = true
onMeasured(it.size)
},
content = { content() },
)
}
Stylianos Gakis
08/14/2024, 12:38 PMwithoutPlacement
does it not just work?
And try by having the onPlaced
modifier before/after to see if that makes any difference.
Btw all of this measuring and the returning without rendering makes me feel like something fishy is going on 😄 Are you sure this is the only approach you got to solve what you're solving?Tgo1014
08/14/2024, 12:39 PMTgo1014
08/14/2024, 12:43 PMmodifier = Modifier
.onPlaced {
isMeasured = true
onMeasured(it.size)
}
.withoutPlacement(),