Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created Jun 27, 2022
Embed
What would you like to do?
windowsizeclass
value class WindowWidthSizeClass private constructor(private val value: String) {
companion object {
/** Represents the majority of phones in portrait. */
val Compact = WindowWidthSizeClass("Compact")
/**
* Represents the majority of tablets in portrait and large unfolded inner displays in
* portrait.
*/
val Medium = WindowWidthSizeClass("Medium")
/**
* Represents the majority of tablets in landscape and large unfolded inner displays in
* landscape.
*/
val Expanded = WindowWidthSizeClass("Expanded")
/** Calculates the [WindowWidthSizeClass] for a given [width] */
internal fun fromWidth(width: Dp): WindowWidthSizeClass {
require(width >= 0.dp) { "Width must not be negative" }
return when {
width < 600.dp -> Compact
width < 840.dp -> Medium
else -> Expanded
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment