Hello :android-wave: Just checking because I haven...
# compose
c
Hello 👋 Just checking because I haven't seen any new information in a while but for our themes to be respected in compose previews we will need to wrap all of our previews in our compose theme, right? Or is there a better way now?
z
That's still the case currently. Maybe in the future there could be some kind of way to define a wrapper composable for all previews like @PreviewWrapper
t
I’ve opened a issue some time ago to give us devs some api to create our own previews, which in case it happens, you could make a wrapper for the theme. Give a +1 if you can https://issuetracker.google.com/issues/307987905 🙂
c
Thanks for the replies. Hopefully we get something soon 🙂 We have a lot of previews 😅
s
Copy code
<template name="prev" value="@com.hedvig.android.core.designsystem.preview.HedvigPreview
@androidx.compose.runtime.Composable
private fun Preview$NAME$() {
  com.hedvig.android.core.designsystem.theme.HedvigTheme {
    androidx.compose.material3.Surface(color = androidx.compose.material3.MaterialTheme.colorScheme.background) {
        $NAME$($END$)
    }
  }
}" description="Create @Preview composable function" toReformat="true" toShortenFQNames="true">
  <variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
  <context />
</template>
Take this live template and copy it. Go over to your IDE at
Preferences | Editor | Live Templates
, then go to AndroidComposePreview and right click and paste in there. Replace the HedvigTheme with your own theme and
HedvigPreview
with your own preview and you’re done. HedvigPreview is this but I think in the latest alphas at least the compose libraries provide dark/light mode preview by default in the library itself, so you don’t need your own.
😲 1
c
Thanks! We also have templates for previews but don't have the theme in there so I'll add that 👍 . Still wishing for some sort of annotation or place we could define and all previews would inherit from