Is there a better way of previewing all my composa...
# compose
m
Is there a better way of previewing all my composables in light and dark mode, without having to duplicate every @Preview function?
f
You can add multiple @Preview annotations with different args.
1
a
You could use a PreviewParameterProvider that provides all the color schemes your app uses, something like:
Copy code
class ThemedPreviewParameterProvider : PreviewParameterProvider<Colors> {
    override val values: Sequence<Colors>
        get() = ...
}

@Preview
@Composable
private fun Preview(@PreviewParameter(ThemedPreviewParameterProvider::class) colors: Colors) {
    MyAppTheme(colors = colors) {
        previewContent()
    }
}
🙌 2
m
Thank you, I didn't realize you can add multiple
@Preview
annotations, that's convenient!
c
Yep definitely use multiple annotations! Also a good way to check things like change in fontScale and locales
PreviewParameterProvider
is also very useful for passing different mock data
m
Hmm, I wish I could define all the preview combination I need in one place and use something like
@PreviewAll(MySettings)
. The PreviewParameterProvider is powerful, but a bit verbose.
c
Fair enough! We’ve been thinking through improving Preview APIs in general and this certainly has come up 🙂