Is there a way to get the right `WindowSizeClass` ...
# compose
s
Is there a way to get the right
WindowSizeClass
when inside a composable preview? If for example in preview I’ve set
device = "spec:width=Xdp,height=Ydp,dpi=240",
which would end up making it look like a wide tablet, can I somehow get the WindowSizeClass to look at those values instead? Right now I am in reality making some decisions which render the UI differently in such screens, but in the previews this is not reflected since I have to construct one of these objects manually, like
WindowSizeClass.calculateFromSize(DpSize(500.dp, 300.dp)),
which obviously don’t match what the preview actually shows.
a
You can use
screenWidthDp
and
screenHeightDp
from
LocalConfiguration.current
. They should be good enough for previews.
s
Yup, this seems to do exactly what I want, thanks!