Rick Regan
11/03/2021, 3:47 PMBoxWithConstraints
does not look like the right tool for that. For example, on a Pixel 4A, BoxWithConstraints
(at the top level, not within a Scaffold
) will give maxWidth
392.dp and maxHeight
785.dp in portrait, and maxWidth
801.dp and maxHeight
348.dp in landscape. I'd like to know that 801.dp is the max, even if the app starts in portrait. Is there a way to do that?
| Edit: Rationale in thread.Rick Regan
11/03/2021, 4:12 PMSideEffect
without introducing a noticeable delay before the new UI displays on the new configuration.)
(The difference between 785.dp and 801.dp might not change the maximum number of elements in this example, but it seems in general better to have the exact number.)Joseph Hawkes-Cates
11/03/2021, 5:14 PMtad
11/03/2021, 10:24 PMfun Context.findActivity(): Activity? {
var context = this
while (context is ContextWrapper) {
if (context is Activity) return context
context = context.baseContext
}
return null
}
@Composable
fun ComposableFun() {
val context = LocalContext.current
val maxDimen = remember {
WindowMetricsCalculator.getOrCreate()
.computeMaximumWindowMetrics(context.findActivity!!)
.bounds
.toComposeRect()
.maxDimension
}
}
tad
11/03/2021, 10:28 PMWindowInfoRepository
to get a flow of current WindowMetrics
values to use (say via collectAsState
), which can be useful for supporting split-screen without relying on BoxWithConstraints
or SubcomposeLayout
.Zach Klippenstein (he/him) [MOD]
11/03/2021, 10:38 PMRick Regan
11/04/2021, 12:12 PMmax(max(maxWidth, maxHeight), max(maxWidth, maxHeight))
which in my example is max(max(392.dp, 785.dp), max( 801.dp, 348.dp)) = 801.dpZach Klippenstein (he/him) [MOD]
11/04/2021, 4:16 PM