-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds step 6.b - Adds getWindowSize for measuring any components requi…
…ring measurements of screen
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
composeApp/src/androidMain/kotlin/app/academy/utils/WindowSize.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
7 changes: 7 additions & 0 deletions
7
composeApp/src/commonMain/kotlin/app/academy/utils/WindowSize.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
composeApp/src/iosMain/kotlin/app/academy/utils/WindowSize.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |