Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created June 27, 2022 01:23
Show Gist options
  • Save skydoves/1ed195d2bb2d9c45d5ff2d2da16ec820 to your computer and use it in GitHub Desktop.
Save skydoves/1ed195d2bb2d9c45d5ff2d2da16ec820 to your computer and use it in GitHub Desktop.
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