mars885 / gamedge

An Android application for browsing video games and checking the latest gaming news from around the world.
Apache License 2.0
689 stars 65 forks source link

Create a custom `@Preview` annotation as a shortcut for both light & dark themes #201

Closed mars885 closed 3 months ago

mars885 commented 2 years ago

Apparently, starting from Compose 1.2, it's possible to create a single annotation for previewing multiple configurations of a particular composable instead of duplicating @Preview multiple times everywhere.

However, as of Jetpack Compose version 1.2 and Android Studio Chipmunk, preview just don't work. Therefore, as soon as previews get fixed, create a single preview annotation and use it for previewing composables. Something like this:

@Preview
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
annotation class GamedgePreview

Then, use it like so:

@GamedgePreview
@Composable
private fun GameInfoLoadingStatePreview() {
  // ...
}
mars885 commented 3 months ago

Jetpack Compose has now multipreviews out of the box. See this.