Suresh Maidaragi
03/12/2024, 10:20 AMval container = LocalWindowInfo.current
val screenHeight = with(LocalDensity.current) {
container.containerSize.height.dp.toPx()
}
error : Unresolved reference: containerSize
Andrey Larionov
03/31/2024, 9:49 AMcontainerSize
hint in commonMain
, but containerSize
is not marked as actual
value under the hood
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:
@Composable
expect fun getScreenWidth(): Dp
Android implementation:
@Composable
actual fun getScreenWidth() = LocalConfiguration.current
.screenWidthDp
.dp
Others:
@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun getScreenWidth() = LocalWindowInfo.current
.containerSize
.width
.dp
Suresh Maidaragi
04/10/2024, 9:09 AM