Hi all. I’m looking to draw a composable and all o...
# compose
g
Hi all. I’m looking to draw a composable and all of its content into a Bitmap for screenshot testing, including stuff currently scrolled outside of the bounds of the device window. Is it possible?
j
Maybe take a look at
DesktopScreenshotTestRule
👀 2
g
Thought about this last night and didn’t get super far, but not due to any compose limitations. More because I have no idea to calculate how tall the window needs to be to fit all of the content without any scrolling, particularly with lazy content
with non-lazy content you might be able to hack something together by traversing semantic nodes
j
You could do it with two passes. In the first pass, pretend to be implementing a custom layout, as custom layouts have the opportunity to measure their children. Then in the second pass, you know how large the child will want to be, you can create a canvas of the appropriate size. Or, if it is for a screenshot test, you can probably just choose a height for the container that is very large (much larger than intended size of content) to ensure there is enough room. It's not like the maximum size needs to be exact, doesn't need to be pretty, just needs to allow everything to be rendered.
You can look at the implementation of Column for a sample layout widget that measures its child.
g
Yeah I tried to do the 2 pass approach. I measured child content without a max height constraint. But what ended up happening is that any screen trying to “fill” the height (e.g. with a weight modifier) ended up as 0 height (since you can’t fill infinity).
It’s not like the maximum size needs to be exact, doesn’t need to be pretty, just needs to allow everything to be rendered.
This is a good point. I could allow devs to just choose a window height per test. Maybe that’s the simple answer here