paparazzi
paparazzi copied to clipboard
Problem with compose and weight / verticalScroll modifiers
I'm using the current snapshot version via classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:1.0.0-SNAPSHOT'
to get compose support wich works already great but when I snapshot a composable which have special modifiers in it, I run into problems.
Modifier.weight()
When weight
is used on a composable, this single one is ignored and does not show up on the snapshot. Others around it are still fine.
I'm using this modifier for the texts on a dialog so that the message gets more space than the title. When taking a paparazzi snapshot, the contents whole text is gone because it's inside a Column using the weight-modifier:
Modifier.verticalScroll()
When using verticalScroll
the whole snapshotis black / empty.
I'm using this modifier for the message on a dialog it can be scrolled when too long. When taking a paparazzi snapshot, the whole snapshot is broken:
Can you provide a sample project/repro?
Sure. And as always, during creation of the example, I was able to narrow down the source of my problem 😊. Please have a look at the example at https://github.com/hardysim/paparazzi-weight-example:
I'm trying to use a DeviceConfig
where screenHeight
and screenWidth
is set to 1
. The idea was that the snapshot-image is only as big as it needs to be (just like the preview in Android Studio). The renderingMode
is set to FULL_EXPAND
, so the image will expand as needed.
https://github.com/hardysim/paparazzi-weight-example/blob/master/mylibrary/src/test/java/com/example/mylibrary/ComposeTest.kt#L17
This works fine until I test a composable which uses a weight()
- or verticalScroll()
-modifier. When leaving the DeviceConfig
untouched, the snapshot-images are rendered correctly (but bigger than they need to be).
So it seems like this is no bug but I want to ask: How can I get an "only as big as necessary" snapshot-image instead of one as big as the entire screen. Is this possible?
How can I get an "only as big as necessary" snapshot-image instead of one as big as the entire screen. Is this possible?
It is now as of #497 and #655.
Like so:
@get:Rule
val paparazzi = Paparazzi(
maxPercentDifference = 0.1,
deviceConfig = DeviceConfig.NEXUS_5,
renderingMode = SessionParams.RenderingMode.SHRINK,
showSystemUi = false
)
After cloning the sample and updating:
compose =>1.3.1
kotlin => 1.7.10
paparazzi => 1.2.0-SNAPSHOT
compileSdk = 33
AGP to 7.3.1
I get the following snapshot:
Here's its @Preview
image: