Hi everyone. I discovered an interesting optimizat...
# compose-android
s
Hi everyone. I discovered an interesting optimization while working on our project, and I thought it was worth sharing. I don’t know if it’s related to Compose or Android system, but it’s intriguing. Details in the thread 🧵K
While stacking multiple composable widgets inside a Box, I noticed something curious in the Layout Inspector. When widgets had different sizes to match their graphics content, drawn on the canvas using the Modifier.drawBehind, they were rendered in separate layers. I added some magenta bounding box lines to highlight the different sizes, and the Layout Inspector 3D view clearly showed each layer stacked on top of the others.
layered_rendering.mov
However, when I made all the widgets the same size, stretching them to the layout of the screen and using transformed coordinates for drawing graphics, the visual output stayed the same, the Layout Inspector showed a single collapsed layer. The boundaries stretched to match the parent layout, and the 3D view no longer displayed distinct layers.
collapsed_layers_rendering.mov
Both variants have the same number of composable widgets, but the system draws them differently. It’s quite intriguing, and I thought it was worth sharing 😄
👍 5
neat 1
👍🏽 1
a
There is
Modifier.toolingGraphicsLayer()
to add a layer in the inspector.
s
Okay, thanks for the information. But that's not quite what I was getting at 🙂