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.
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.
I had another issue causing the same behaviour.
@Preview
@Composable
fun MyComposablePreview(
@PreviewParameter(MyComposableStateProvider::class) state: MyComposableState
) = MyComposable(state)
@Preview
@Composable
fun MyComposablePreview(
@PreviewParameter(MyComposableStateProvider::class) state: MyComposableState
) {
MyComposable(state)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.