https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
c

Carlo De Chellis

05/31/2023, 3:02 PM
Hi to all. I'm experimenting Compose for Ios and I would like to know, is there a way to achieve real time WindowSize just like the android composable like this:
Copy code
@Composable
private fun Activity.rememberWindowSize(): WindowSize {
    val configuration = LocalConfiguration.current
    val windowMetrics = remember(configuration) {
        WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(this)
    }
    val windowDpSize = with(LocalDensity.current) {
        windowMetrics.bounds.toComposeRect().size.toDpSize()
    }
    return WindowSize.basedOnWidth(windowDpSize.width)
}
? Thanks in advance.
o

Oleksandr Karpovich [JB]

06/01/2023, 10:11 AM
LocalUIViewController - is a Composition Local you can use to access the UIViewController. Then you can get UIView from it and its frame.
c

Carlo De Chellis

06/01/2023, 10:21 AM
Great!!! Thank you
s

Shubham Tomar

06/01/2023, 12:30 PM
But when I'm trying to access in iosMain in shared module, then using UIViewController.current.view.frame that frame has only variable: align and size So How can I get height and width through that? e.x. : it doesn't work like width and height
Copy code
@Composable
actual fun getScreenDimensions(): Pair<Int, Int> {
    val config = LocalUIViewController.current.view().frame
    return Pair(config.size, config.align)
}
b

Ben Abramovitch

08/11/2023, 5:36 AM
Did you ever figure this out? I need screen dimensions as well for the iOS side
11 Views