Justin Breitfeller
06/08/2022, 4:24 PMSubcomposeLayout
by:
1. Call subcompose
with the passed in width constraints
2. If the resulting placeables are too wide, call subcompose
with constraints that has a minWidth of what was passed to the SubcomposeLayout.
3. I then only place either the horizontal or vertical placeables.
The one problem I’m having with this approach is the semantics tree still knows about the horizontal subcomposition even though I never placed them. Is there a way to remove them or perhaps another way to approach this problem?Adam Powell
06/08/2022, 4:32 PMLayout
composable and avoid subcomposition for this. Use intrinsic sizes to determine whether things fit and then perform final measurement once you've decided the orientationJustin Breitfeller
06/08/2022, 4:59 PMAdam Powell
06/08/2022, 5:01 PMMeasurable
for its minimum intrinsic width given a certain available height, for exampleJustin Breitfeller
06/08/2022, 5:01 PMAdam Powell
06/08/2022, 5:03 PMLayout
composable rather than returning an object directly like thatOleksandr Balan
06/08/2022, 5:28 PMminIntrinsicWidth()
is used in this sample:
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1648551227037639?thread_ts=1648467352.438719&cid=CJLTWPH7S
As for me it would be useful to mention this approach in docs you linked.Justin Breitfeller
06/08/2022, 5:42 PMLayout(modifier = modifier, content = content) { measurables, constraints ->
val totalWidth = measurables.sumOf {
it.minIntrinsicWidth(constraints.maxHeight)
}
if (totalWidth > constraints.maxWidth) {
columnLayout(measurables, constraints)
} else {
rowLayout(measurables, constraints)
}
}
I ended up doing this which seems to work! Thanks!