-
-
Save skydoves/1ed195d2bb2d9c45d5ff2d2da16ec820 to your computer and use it in GitHub Desktop.
windowsizeclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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