Skip to content

Commit

Permalink
Adds step 6.b - Adds getWindowSize for measuring any components requi…
Browse files Browse the repository at this point in the history
…ring measurements of screen
  • Loading branch information
aldefy committed Jun 30, 2024
1 parent a7f35ef commit 37ad2e8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.academy.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp

@Composable
actual fun getWindowSize(): DpSize {
val screen = LocalConfiguration.current
return DpSize(screen.screenWidthDp.dp, screen.screenHeightDp.dp)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.academy.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.DpSize

@Composable
expect fun getWindowSize(): DpSize
20 changes: 20 additions & 0 deletions composeApp/src/iosMain/kotlin/app/academy/utils/WindowSize.ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.academy.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import kotlinx.cinterop.ExperimentalForeignApi
import platform.UIKit.UIScreen

@Composable
@OptIn(ExperimentalComposeUiApi::class)
actual fun getWindowSize(): DpSize {
val screen = LocalWindowInfo.current.containerSize
val width = screen.width
val height = screen.height
// Convert points to dp
val density = UIScreen.mainScreen.scale
return DpSize((width / density).dp, (height / density).dp)
}

0 comments on commit 37ad2e8

Please sign in to comment.