Skip to content

Instantly share code, notes, and snippets.

@parthdesai1208
Last active January 4, 2023 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parthdesai1208/4f5ba0a8a2b1c3ea1daede6a20c6808a to your computer and use it in GitHub Desktop.
Save parthdesai1208/4f5ba0a8a2b1c3ea1daede6a20c6808a to your computer and use it in GitHub Desktop.
Preview
@Preview(group = "phone", name = "light", device = Devices.PIXEL_4_XL, showSystemUi = true)
@Preview(
group = "phone",
name = "dark",
uiMode = UI_MODE_NIGHT_YES,
device = Devices.PIXEL_4_XL,
showSystemUi = true,
showBackground = true
)
annotation class Phone
@Preview(
group = "phone",
name = "land-light",
showSystemUi = true,
device = Devices.AUTOMOTIVE_1024p,
widthDp = 760,
heightDp = 360//"spec:width=760dp,height=360dp,dpi=533.94,isRound=false,chinSize=0dp,orientation=landscape"
)
@Preview(
group = "phone",
name = "land-dark",
showSystemUi = true,
uiMode = UI_MODE_NIGHT_YES,
device = Devices.AUTOMOTIVE_1024p,
widthDp = 760,
heightDp = 360//"spec:width=2026.67dp,height=960dp,dpi=537,isRound=false,chinSize=0dp,orientation=landscape"
)
annotation class PhoneInLandscape
@Preview(group = "tablet", name = "light", device = Devices.PIXEL_C)
@Preview(group = "tablet", name = "dark", uiMode = UI_MODE_NIGHT_YES, device = Devices.PIXEL_C)
annotation class Tablet
@Preview(
group = "tablet",
name = "land-light",
showSystemUi = true,
device = Devices.AUTOMOTIVE_1024p,
widthDp = 900,
heightDp = 1280
)
@Preview(
group = "tablet",
name = "land-dark",
showSystemUi = true,
uiMode = UI_MODE_NIGHT_YES,
device = Devices.AUTOMOTIVE_1024p,
widthDp = 900,
heightDp = 1280
)
annotation class TabletInPortrait
@Preview(group = "foldable", name = "light", device = Devices.FOLDABLE)
@Preview(group = "foldable", name = "dark", uiMode = UI_MODE_NIGHT_YES, device = Devices.FOLDABLE)
annotation class Foldable
@Preview(group = "desktop",name = "light", device = Devices.DESKTOP)
@Preview(group = "desktop",name = "dark", uiMode = UI_MODE_NIGHT_YES, device = Devices.DESKTOP)
annotation class Desktop
@Phone
@PhoneInLandscape
@Tablet
@TabletInPortrait
@Foldable
@Desktop
annotation class AllDevices
use it like,
@AllDevices
@Composable
fun TextComposePreview() {
...
}
****************************************************************************************************************************************
combined preview
****************************************************************************************************************************************
@Preview(name = "small font", group = "font scales", fontScale = 0.5f)
@Preview(name = "large font", group = "font scales", fontScale = 1.5f)
annotation class FontScalePreviews
@Preview(name = "dark theme", group = "themes", uiMode = UI_MODE_NIGHT_YES)
@FontScalePreviews //definition above
annotation class CombinedPreviews
@CombinedPreviews
@Composable
fun HelloWorldPreview() {
...
}
***************************************************************************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment