cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.23k stars 211 forks source link

EditModeInterceptor breaks GooglePay Ui and other AndroidViews #1390

Closed jamesrapadmi closed 1 month ago

jamesrapadmi commented 2 months ago

Description The edit mode interceptor forces all views to have isInEditMode() false. This causes them to try network requests or other behaviour that is inappropriate for screenshot testing. There's currently no way to change this behaviour.

Steps to Reproduce Create a preview using an AndroidView composable with a view using isInEditMode(), e.g. the GooglePay com.google.pay.button.PayButton composable

@Preview
@Composable
fun Example() {
    PayButton(
        onClick = {},
        allowedPaymentMethods = "DUMMY",
    )
}

Viewing the preview locally is fine, as isInEditMode() returns true. However, screenshotting this with Paparazzi doesn't work as the view tries to load the runtime behaviour.

Expected behaviour I expected isInEditMode() to be true for all Paparazzi contexts. However, there should be a way to set this setting to avoid views loading runtime behaviour.

Additional information:

Screenshots Preview in Android studio:

Screenshot 2024-04-23 at 12 41 01
jrodbx commented 1 month ago

This is by design. Paparazzi is of the opinion that you should never want to do this. It wants you to run your actual code!

It's unfortunate that com.google.pay.button.PayButton bundles network logic in its UI. We encountered a similar situation with Google's Map Composable; a suggested workaround for that can be found here: https://github.com/cashapp/paparazzi/issues/709#issuecomment-1693810857