Colton Idle
09/05/2022, 8:09 PMModifier.onSizeChanged {
Log.e("DEBUG", "height: ${it.height} and totalHeight: $totalSize")
totalSize += it.height
}
E/DEBUG: height: 340 and totalHeight: 340
E/DEBUG: height: 340 and totalHeight: 680
E/DEBUG: height: 340 and totalHeight: 1020
...
then crashes
All I'm trying to do is fine the height of a composable after it's been drawn so I know it's height in pixels.
I'm confused because this wasn't happening in the past, but it seems like in alpha2 or alpha3 something changed?Filip Wiesner
09/05/2022, 8:17 PMInvoked with the size of the modified Compose UI element when the element is first measured or when the size of the element changes.
There are no guaranteeswill not be re-invoked with the same size.onSizeChanged
Colton Idle
09/05/2022, 8:26 PMColton Idle
09/05/2022, 8:31 PMFrancesc
09/05/2022, 8:37 PMFrancesc
09/05/2022, 8:45 PMColton Idle
09/05/2022, 9:19 PMgotAHeightValueAlready = false
and set it to true when I get a value for now. I know that the height isn't changing once itst laid out, but I guess I will try to find a more permanent fix for this.Francesc
09/05/2022, 9:40 PMjossiwolf
09/05/2022, 9:57 PMtotalSize
? The size you get from onSizeChanged
is absoluteColton Idle
09/05/2022, 10:16 PMColton Idle
09/05/2022, 10:17 PMFrancesc
09/05/2022, 10:28 PMFrancesc
09/05/2022, 10:29 PMFrancesc
09/05/2022, 10:31 PMColton Idle
09/05/2022, 10:41 PMBen Trengrove [G]
09/06/2022, 12:26 AMval heights = remember { mutableStateListOf(0, 0) }
val totalHeight = heights.sum()
Text("$totalHeight")
LazyColumn {
itemsIndexed(snacks) { index, snack ->
SnackItem(
snack,
onSnackClick,
Modifier.onSizeChanged {
if (index <= 1) {
heights[index] = it.height
}
}
)
}
}
Colton Idle
09/07/2022, 1:33 PMColton Idle
09/09/2022, 12:50 PM