Hi there, Started seeing following when I run And...
# multiplatform
s
Hi there, Started seeing following when I run Android build when using the containerSize to get the screen height, can someone help to check..
Copy code
val container = LocalWindowInfo.current
val screenHeight = with(LocalDensity.current) {
    container.containerSize.height.dp.toPx()
}

error : Unresolved reference: containerSize
a
Hey @Suresh Maidaragi I don’t know why IDE suggests
containerSize
hint in
commonMain
, but
containerSize
is not marked as
actual
value under the hood
Copy code
actual interface WindowInfo {
    actual val isWindowFocused: Boolean

    actual val keyboardModifiers: PointerKeyboardModifiers
        get() = WindowInfoImpl.GlobalKeyboardModifiers.value
    
    val containerSize: IntSize get() = IntSize.Zero
}
so you can’t use it in
commonMain
So you need to define your own
expect
function like this:
Copy code
@Composable
expect fun getScreenWidth(): Dp
Android implementation:
Copy code
@Composable
actual fun getScreenWidth() = LocalConfiguration.current
    .screenWidthDp
    .dp
Others:
Copy code
@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun getScreenWidth() = LocalWindowInfo.current
    .containerSize
    .width
    .dp
s
thanks @Andrey Larionov that helped a lot @thanks