androidandroid-jetpack-compose

JetpackCompose @PreviewParameter causes preview to disappear


I've been exploring Jetpack Compose lately and discovered this very weird scenario where my @Preview is not showing and Android Studio is literally showing blank empty. No warnings or errors are shown.

This happens when I add @PreviewParameter to my composable function parameter.


Solution

  • The stupid solution was… It turns out that I had my PreviewParameterProvider declared in private and turning it to public or simply removing the visibility modifier fixed it.

    class MyProvider : PreviewParameterProvider<MyClass> {
        ...
    }
    

    This wasn't even documented.

    I hope Google will make it clear in the documentation or at least give an error in Android Studio so developers won't encounter this frustrating and time-wasting scenario.