airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.1k stars 107 forks source link

Support for AlertDialog previews #235

Open Skeletonxf opened 2 years ago

Skeletonxf commented 2 years ago

I'm trying to use Showkase to run screenshot tests which include material3 AlertDialogs but the tests are failing with this error:

com.example.ShowkaseScreenshots_ShowkcaseCodegen > composable_screenshot_test_1[Pixel_2_API_31(AVD) - 12] FAILED
        java.lang.AssertionError: Failed to capture a node to bitmap
        Reason: Expected exactly '1' node but found '2' nodes that satisfy: (isRoot)

Minimal example:

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text

@Preview
@Composable
fun AlertDialogPreview() {
    AlertDialog(
        onDismissRequest = {},
        confirmButton = {
            Text("Ok")
        },
        title = {
            Text("title")
        },
        text = {
            Text("description")
        }
    )
}

When I browse to the AlertDialogPreview in the Showkase browser it also takes up the full screen and stops me navigating since I can't close it.

alert-dialog-component-browser

Thanks

vinaygaba commented 2 years ago

Thanks for reporting the issue. I'm going to play with it and see what's going on!

MessiasLima commented 1 year ago

Any update on this?

Skeletonxf commented 1 year ago

Switching to paparazzi instead of shot mostly resolves the screenshot test failure issues (paparazzi will still fail if there is no UI under the popup so alert dialogs have to be screenshotted against dummy backgrounds). The latter issue in the Showkase browser is unchanged as far as I am aware.

vinaygaba commented 1 year ago

I had very briefly looked at it and did not come up with an obvious way to resolve this in the Showkase browser. I'm open to ideas on how I can capture the separate window (I think?) that the alert typically lives in and render it inline in the browser.