rememberScreenSize
Remembers and provides the current screen size in density-independent pixels.
This composable function calculates the screen dimensions based on the current window container size and density. The result is remembered and will be recalculated when the density or window information changes.
@Composable
fun AdaptiveContent() {
val screenSize = rememberScreenSize()
Column {
Text("Screen: ${screenSize.widthDp} x ${screenSize.heightDp}")
when {
screenSize.widthDp < 480.dp -> CompactLayout()
screenSize.widthDp < 840.dp -> MediumLayout()
else -> ExpandedLayout()
}
}
}
Content copied to clipboard
Return
ScreenSize containing current screen dimensions