3

I would like to create an annotation called @MyComposablePreview that is composed of:

@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = true,
    name = "Light Mode"
)
@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_YES,
    showBackground = true,
    name = "Dark Mode"
)
@Composable

So that I could call it in a composable function like this:

@MyComposablePreview
fun CardPreiview() {
    //Code of preview
}

Is it possible to do this in jetpack compose? I tried to use annotated classes but I couldn't :/

Pierre Vieira
  • 2,252
  • 4
  • 21
  • 41

1 Answers1

0

You can use this:

@Preview(
  name = "Light",
  group = "Light",
  showBackground = true,
  backgroundColor = 0xffEEEEEE,
  uiMode = UI_MODE_NIGHT_NO,
  fontScale = 1f
)
@Preview(
  name = "Dark",
  group = "Dark",
  showBackground = true,
  backgroundColor = 0xff444444,
  uiMode = UI_MODE_NIGHT_YES,
  fontScale = 1f
)
@Preview(
  name = "Light - Large font",
  group = "Light",
  showBackground = true,
  backgroundColor = 0xffEEEEEE,
  uiMode = UI_MODE_NIGHT_NO,
  fontScale = 2f
)
@Preview(
  name = "Dark - Large font",
  group = "Dark",
  showBackground = true,
  backgroundColor = 0xff444444,
  uiMode = UI_MODE_NIGHT_YES,
  fontScale = 2f
)
annotation class MyComposablePreview
jacksonfdam
  • 411
  • 5
  • 5