Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created January 20, 2022 05:27
Show Gist options
  • Save skydoves/c84c4197f71235fc2863f2b2b0d84529 to your computer and use it in GitHub Desktop.
Save skydoves/c84c4197f71235fc2863f2b2b0d84529 to your computer and use it in GitHub Desktop.
windowsize
// 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