xxfast
06/07/2023, 1:25 AMfun Main(): UIViewController = ComposeUIViewController {
BoxWithConstraints {
val windowSizeClass: WindowSizeClass = WindowSizeClass.calculateFromSize(DpSize(maxWidth, maxHeight))
MaterialTheme {
// My app
}
}
}
This feels like a hack. Is there a better way to get these sizes? A quick glance at ComposeWindow
(ComposeUIViewController
) implementation shows me that ComposeLayer
getting updated on viewWillTransitionToSize
, but this seems to be private.Sunil Kumar
06/11/2023, 10:39 AMxxfast
06/11/2023, 10:43 AM// commonMain
@Suppress("ConvertSecondaryConstructorToPrimary") // To mirror android api
expect class WindowSizeClass {
val widthSizeClass: WindowWidthSizeClass
val heightSizeClass: WindowHeightSizeClass
private constructor(
widthSizeClass: WindowWidthSizeClass,
heightSizeClass: WindowHeightSizeClass
)
}
// androidMain
import androidx.compose.material3.windowsizeclass.WindowSizeClass
actual typealias WindowSizeClass = WindowSizeClass
// nonAndroidMain
actual typealias WindowSizeClass = CommonWindowSizeClass // basically copy-pasta of android implementation
Working sample hereSunil Kumar
06/11/2023, 10:51 AM