A window size class buckets the space your window actually has, not the device's screen, so a tablet in split screen can be compact. Width is what usually decides the layout:
| Width class | Window width | Typical device |
|---|---|---|
| Compact | under 600 dp | phone in portrait |
| Medium | 600 to 839 dp | tablet or unfolded foldable in portrait |
| Expanded | 840 to 1199 dp | tablet in landscape, phone in landscape |
| Large and Extra-large | 1200 dp and up | desktop windows, large tablets |
currentWindowAdaptiveInfoV2() returns the class as State, recomputed on rotation, resize and fold, so the composables that read it recompose (the older currentWindowAdaptiveInfo() is deprecated in adaptive 1.3.0, with a compiler warning to use V2 "to support L and XL width size classes"). Compare with breakpoints, never with exact sizes:
@Composable
fun LogWindowInfo() {
val info = currentWindowAdaptiveInfoV2() // recomputed on every window change
val size = info.windowSizeClass
val width = when {
size.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_LARGE_LOWER_BOUND) -> "LARGE"
size.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_EXPANDED_LOWER_BOUND) -> "EXPANDED"
size.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND) -> "MEDIUM"
else -> "COMPACT"
}
SideEffect {
Log.d(TAG, "width $width (>= ${size.minWidthDp} dp), posture ${info.windowPosture}")
Log.d(TAG, "mode: ${postureMode(info.windowPosture)}")
}
}Logged in portrait, after rotating to landscape, and after rotating back:
D/BookNestAdaptive: width COMPACT (>= 0 dp), posture Posture(isTabletop=false, hinges=[]) D/BookNestAdaptive: mode: flat: no separating hinge D/BookNestAdaptive: width EXPANDED (>= 840 dp), posture Posture(isTabletop=false, hinges=[]) D/BookNestAdaptive: mode: flat: no separating hinge D/BookNestAdaptive: width COMPACT (>= 0 dp), posture Posture(isTabletop=false, hinges=[]) D/BookNestAdaptive: mode: flat: no separating hinge
minWidthDp is the class's lower bound, not the window's width. Height classes (compact under 480 dp, medium to 899, expanded above) matter for landscape phones, where a tall layout may not fit.