cashapp / paparazzi

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

DropdownMenu not appearing in snapshots #1693

Open corentin-stamper opened 2 days ago

corentin-stamper commented 2 days ago

Description DropdownMenu not appearing in snapshots

Steps to Reproduce

package paparazzi.dropdown_menu

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import app.cash.paparazzi.Paparazzi
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class DropdownMenuTest {

    @get:Rule
    val paparazzi = Paparazzi()

    @Test
    fun test() {
        paparazzi.snapshot {
            MaterialTheme {
                Column(
                    modifier = Modifier
                        .fillMaxSize()
                        .background(Color.White)
                        .padding(8.dp)
                ) {
                    Box {
                        Text(
                            text = "Label 1",
                        )

                        DropdownMenu(
                            expanded = true,
                            onDismissRequest = {},
                        ) {
                            DropdownMenuItem(
                                text = {
                                    Text(
                                        text = "Label 1",
                                    )
                                },
                                onClick = {}
                            )
                            DropdownMenuItem(
                                text = {
                                    Text(
                                        text = "Label 2",
                                    )
                                },
                                onClick = {}
                            )
                            DropdownMenuItem(
                                text = {
                                    Text(
                                        text = "Label 3",
                                    )
                                },
                                onClick = {}
                            )
                        }
                    }
                }
            }
        }
    }
}

Expected behavior The DropdownMenu appears

Additional information:

Screenshots

Image

geoff-powell commented 2 days ago

Thanks for logging this issue! I need to dig in to how LayoutLib in Android studio gets this to render but it looks like the issue is due to animation of the drop down.

Paparazzi

Used accessibility render extension to better identify the dropdown items. (video is 120 fps, 1 sec slowed to show the animation better) Image

Android Studio

Android Studio Preview shows this with your example (I added the button for my own testing) Image

Emulator

Image

So this is rendering mostly as expected. Since we have an issue where compose animations aren't timed correctly using offsetMillis param in paparazzi.snapshot() my suggestion would be to use paparazzi.snapshot(view, ..., offsetMillis = 5000) where 5000 is arbitrary to expected result.