Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// gradle dependecies (app.gradle)
dependencies {
implementation "androidx.compose.material3:material3:<latest_version>"
implementation "androidx.compose.material3:material3-window-size-class:<latest_version>"
}
// Activity
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val windowSizeClass = calculateWindowSizeClass(this)
MyApp(windowSizeClass = windowSizeClass)
}
}
}
@Composable
fun MyApp(windowSizeClass: WindowSizeClass) {
when (windowSizeClass.widthSizeClass) {
WindowWidthSizeClass.Compact -> {
CompactUI()
}
else -> {
ExpandedUI()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment