-
-
Save skydoves/c84c4197f71235fc2863f2b2b0d84529 to your computer and use it in GitHub Desktop.
windowsize
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
// Copyright 2022 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
sealed class WindowSize(val size: DpSize) { | |
class Compact(windowDpSize: DpSize) : WindowSize(windowDpSize) | |
class Medium(windowDpSize: DpSize) : WindowSize(windowDpSize) | |
class Expanded(windowDpSize: DpSize) : WindowSize(windowDpSize) | |
} | |
fun getWindowSizeClass(windowDpSize: DpSize): WindowSize = when { | |
windowDpSize.width < 0.dp -> throw IllegalArgumentException("Dp value cannot be negative") | |
windowDpSize.width < 600.dp -> WindowSize.Compact(windowDpSize) | |
windowDpSize.width < 840.dp -> WindowSize.Medium(windowDpSize) | |
else -> WindowSize.Expanded(windowDpSize) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment