Rick Regan
11/08/2021, 3:24 PM@Composable
fun Dimensions() {
BoxWithConstraints {
val orientation = if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) "P" else "L"
println("$orientation: w = $maxWidth, h = $maxHeight")
}
}
I started in portrait orientation and then rotated the device left 8 times (with android:screenOrientation="fullUser"
to allow it to render upside down). There were three unexpected things about the output:
(1) Duplicate messages for a given rotation
(2) Change in orientation is not in sync with the change in dimensions
(3) Incorrect intermediate dimensions
(1) I suppose is just Compose working as advertised (duplicate recompositions), but (2) and (3) I don't understand.
(See 🧵for details.)Rick Regan
11/08/2021, 3:25 PMstartup
P: w = 392.72726.dp, h = 785.4545.dp
P: w = 392.72726.dp, h = 785.4545.dp <= (1) duplicate message
rotate L
L: w = 392.72726.dp, h = 785.4545.dp <= (2) new orientation, old dimensions
L: w = 801.4545.dp, h = 348.72726.dp
L: w = 801.4545.dp, h = 348.72726.dp
rotate L
P: w = 801.4545.dp, h = 348.72726.dp
P: w = 392.72726.dp, h = 736.0.dp
P: w = 392.72726.dp, h = 736.0.dp
rotate L
L: w = 392.72726.dp, h = 736.0.dp
L: w = 801.4545.dp, h = 277.81818.dp <= (3) incorrect intermediate height
L: w = 801.4545.dp, h = 348.72726.dp
L: w = 801.4545.dp, h = 348.72726.dp
rotate L
P: w = 801.4545.dp, h = 348.72726.dp
P: w = 392.72726.dp, h = 785.4545.dp
P: w = 392.72726.dp, h = 785.4545.dp
rotate L
L: w = 392.72726.dp, h = 785.4545.dp
L: w = 801.4545.dp, h = 348.72726.dp
L: w = 801.4545.dp, h = 348.72726.dp
rotate L
P: w = 801.4545.dp, h = 348.72726.dp
P: w = 392.72726.dp, h = 736.0.dp
P: w = 392.72726.dp, h = 736.0.dp
rotate L
L: w = 392.72726.dp, h = 736.0.dp
L: w = 801.4545.dp, h = 348.72726.dp
L: w = 801.4545.dp, h = 348.72726.dp
rotate L
P: w = 801.4545.dp, h = 348.72726.dp
P: w = 392.72726.dp, h = 785.4545.dp
P: w = 392.72726.dp, h = 785.4545.dp
Adam Powell
11/08/2021, 4:37 PMBoxWithConstraints
subcomposition recomposes in the normal recompose step as a result of LocalConfiguration
changing. Then layout happens and the contents are measured with the new constraints, so BoxWithConstraints
recomposes again, now with the new constraints.Rick Regan
11/08/2021, 6:03 PMAdam Powell
11/08/2021, 9:12 PMRick Regan
11/08/2021, 9:35 PMAdam Powell
11/08/2021, 9:43 PMRick Regan
11/08/2021, 9:47 PM