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.13k stars 107 forks source link

Incorrect width and height when using @Preview annotation #204

Closed ofalvai closed 2 years ago

ofalvai commented 2 years ago

When I'm using the @Preview annotation from Compose, my composables are rendered as tiny squares. They are rendered correctly when I switch to @ShowkaseComposable, but I want to restrict Showkase dependencies to debugImplementation only, so I don't want to import @ShowkaseComposable in any production files.

Looking at the generated code of one @Preview annotated and one @ShowkaseComposable annotated function, the only difference is the width and height parameters:

        ShowkaseBrowserComponent(
            group = "Calendar",
            componentName = "Day legend",
            componentKDoc = "",
            componentKey = """...""",
            isDefaultStyle = false,
            widthDp = -1,
            heightDp = -1,
            component = @Composable { PreviewCalendarDayLegend() }),
        ShowkaseBrowserComponent(
            group = "Calendar",
            componentName = "Pager",
            componentKDoc = "",
            componentKey = """...""",
            isDefaultStyle = false,
            component = @Composable { PreviewCalendarPager() }),

Note: I'm using KSP instead of KAPT for code generation.

vinaygaba commented 2 years ago

Hmm I'll have to take a look at this. KSP is brand new so its possible that some logic could've unintentionally changed 🤔

vinaygaba commented 2 years ago

Also, I need to update some documentation that talks about how Showkase can be added only to the debug builds. I'll do it soon!

andrey-bolduzev commented 2 years ago

Can confirm, I'm seeing the same tiny white squares on beta 10 with kapt as well. Specifying widthDp and heightDp in the @Preview fixes the rendering but is not scalable.

vinaygaba commented 2 years ago

I have a fix up for it!