Anyone know about Multiple Preview in CMP like for...
# compose
m
Anyone know about Multiple Preview in CMP like for Dark, Light Theme and different devices etc
s
You can set width/height in the
@Preview
arguments. I do something like:
Copy code
@Preview
@Composable
fun ExampleLightPreview() {
    MyTheme(isDark = false) {
        ...
    }
}

@Preview
@Composable
fun ExampleDarkPreview() {
    MyTheme(isDark = true) {
        ...
    }
}
I also keep my
WindowSizeClass
in a composition local, so when I want to test that, I can provide it there too. Or you could pass it in as an argument to whichever compose function you're testing if that makes more sense.
m
in native android i use like that i think may be we can do for CMP Project utility class
Copy code
package com.mlbench.truedrop.data.utils

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.ui.tooling.preview.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 = "phone",
    group = "devices",
    device = "spec:width=360dp,height=640dp,dpi=480"
)
@Preview(
    name = "small_phone",
    group = "devices",
    device = "id:small_phone"
)
@Preview(
    name = "foldable",
    group = "devices",
    device = "spec:width=673dp,height=841dp,dpi=480"
)
@Preview(
    name = "tablet",
    group = "devices",
    device = "spec:width=1280dp,height=800dp,dpi=480"
)
annotation class DevicePreviews

@Preview(
    name = "dark theme",
    group = "themes",
    uiMode = UI_MODE_NIGHT_YES,
    showBackground = true
)
@FontScalePreviews
@DevicePreviews
annotation class CompletePreviews
s
You can keep using that in your
androidMain
, you just can't use it in common code.
m
hm thanks for that but i try it can we make similar class for CMP Project in Common Module? What you think about that?
s
If so, I don't know how.
m
hm i try it if i can do but thanks for that