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

Paparazzi + Showkase Integration - java.io.FileNotFoundException (File name too long) #340

Open ss0930 opened 1 year ago

ss0930 commented 1 year ago

I am using showkase-screenshot-testing-paparazzi from https://github.com/airbnb/Showkase/pull/294 to auto-generate snapshots for Composable Previews. For certain previews that have long names, I am running into this issue from Paparazzi https://github.com/cashapp/paparazzi/issues/734. Since the test name and png file name is being generated on Showkase, not sure if there is something I can do on my end.

I am able to get around it by renaming the Preview to something shorter, but would be great to have a fix for this in Showkase itself.

evant commented 11 months ago

Ran into this as well, leaving some notes on how this can be improved:

  1. It appears the generated file names for properties can be aggressively long, including the preview name, the component name, and the group name concatenated together. beta17 was even worse including the package name as well but that appears to be fixed.

    Do we actually need all of those? I'd think the preview function name would be sufficient since you can't have duplicate function names in the source files anyway, but maybe there's something I'm missing there.

  2. If you use preview params it also generates a lamba which is represented by a synthetic class. The name of this lambda is filename$propertyname$1.class which blows it up even more. shortening the filename/property would also help here but you can also go one step further and split it out into a separate function so the lamba isn't generated at all. Something like:

    
    public val MyPreviewNameGroup: List<ShowkaseBrowserComponent> = 
    PreviewStyle()
        .values
        .iterator()
        .asSequence()
        .mapIndexed(::spacingPreviewSpacingExtrasSDKSpacingValues)
        .toList()

private fun myPreviewNameGroup(index: Int, previewParam: Param): ShowkaseBrowserComponent { return ShowkaseBrowserComponent( group = "Group" componentName = "Name", componentKDoc = "", componentKey = ..., isDefaultStyle = false, component = @Composable { MyPreview(param = previewParam) } ) }

vinaygaba commented 11 months ago

@evant The reason all this info is added is because you can you repeated annotations and a single function can actually end up being multiple previews depending on how you are using the preview annotations. I do think that I need to figure out an alternate way to solve this though as hitting this issue could be common if you are using longer and more descriptive names.

For example, here's a file that Paparazzi generated in the sample project --

com.airbnb.android.showkase.screenshot.testing.paparazzi.sample_MyPaparazziShowkaseScreenshotTest_PaparazziShowkaseTest_test_previews[1.Chips**Basic Chip**Default Style,1.Pixel5,1.Ltr,1.DEFAULT]_chips**basic_chip**default_style

I wonder if I can somehow get rid of the earlier portion of the name that's added by Paparazzi by default i.e com.airbnb.android.showkase.screenshot.testing.paparazzi.sample_MyPaparazziShowkaseScreenshotTest_PaparazziShowkaseTest. Do you know if I can somehow configure that?

evant commented 11 months ago

The reason all this info is added is because you can you repeated annotations and a single function can actually end up being multiple previews depending on how you are using the preview annotations

Could you generate multiple properties in the same file or generate a single property that's a list of the components?

evant commented 11 months ago

Actually, just realized that this issue is about the generated paparazzi name. This name is purely generated from the test name so the fix would be separate, happy to open a new issue for generated showkase class names if that makes more sense.

KatieBarnett commented 10 months ago

I'm getting this as well with just Showkase (although actually we plan to use Paparazzi soon as well). Is there a possible workaround? We have a lot of previews and need descriptive names.