I am having weird behaviour with `BoxWithConstrain...
# compose
n
I am having weird behaviour with
BoxWithConstraints
composable. The closure that is being passed to it gets called multiple times with the height being different values each times. There is no animation or no state that can cause it to be recomposed. P.S. I am using
1.0.0-rc01
version of compose. The code and stack trace in 🧵
Copy code
ComposeView(requireContext()).apply {
            layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )
            setContent {
                BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
                    println("<<<<<<<Height ${constraints.maxHeight}")
                    println("<<<<<<<Width ${constraints.maxWidth}")
                    Box(modifier = Modifier.matchParentSize().background(Color.Cyan))
                }
            }
}
Stack trace:
Copy code
I/System.out: <<<<<<<Height 1868
I/System.out: <<<<<<<Width 1080
I/System.out: <<<<<<<Height 2022
I/System.out: <<<<<<<Width 1080
I/System.out: <<<<<<<Height 1868
I/System.out: <<<<<<<Width 1080
I/System.out: <<<<<<<Height 2022
I/System.out: <<<<<<<Width 1080
I/System.out: <<<<<<<Height 1868
I/System.out: <<<<<<<Width 1080
d
Views do not measure in a single pass
t
That wouldn't explain this; I suspect each log there is coming from a new
ComposeView
n
The ComposeView is created in onCreateView of a Fragment. I checked and it got called only once.
@Daniele Segato If I put a Box with swipable modifier inside BoxWithConstraints then the closure that is being passed to BoxWithConstraints gets called multiple times (while swiping) and it affects the performance a lot if you place PlayerView or MapView inside BoxWithConstraints. So in my opinion the body of BoxWithConstraints should only be called if the width or height of the composable changes in which the BoxWithConstraints is added to.
d
Mine was just a theory. I don't use ComposeView yet, not directly
j
Have you solved this? I have the same problem right now. Even with 1.1.0-alpha04.