Skip to content

Commit

Permalink
library: Fix wasmJs get windowSize
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Aug 22, 2024
1 parent 35fc5b9 commit a59e99e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publishing {

// Provide artifacts information required by Maven Central
pom {
name.set("Miuix-like UI")
name.set("miuix")
description.set("A MiuiX-like UI for Kotlin Multiplatform")
url.set("https://github.com/miuix-kotlin-multiplatform/miuix")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "top.yukonga.miuix.kmp"
version = "0.0.1"
version = "0.0.2"
}
7 changes: 4 additions & 3 deletions miuix/src/desktopMain/kotlin/expectUtils.desktop.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.awt.ComposeWindow
import androidx.compose.ui.platform.LocalDensity
import kotlin.math.roundToInt

object WindowSizeProvider {
private var composeWindow: ComposeWindow? = null
Expand All @@ -24,9 +25,9 @@ actual fun getWindowSize(): WindowSize {
val density = LocalDensity.current.density
val windowSize = WindowSizeProvider.getWindowSize()
return WindowSize(
width = (windowSize.width * density).toInt(),
height = (windowSize.height * density).toInt()
width = (windowSize.width * density).roundToInt(),
height = (windowSize.height * density).roundToInt()
)
}

actual fun platform(): Platform = Platform.Desktop
actual fun platform(): Platform = Platform.Desktop
3 changes: 2 additions & 1 deletion miuix/src/iosMain/kotlin/expectUtils.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import androidx.compose.ui.platform.LocalDensity
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.useContents
import platform.UIKit.UIScreen
import kotlin.math.roundToInt

@OptIn(ExperimentalForeignApi::class)
@Composable
Expand All @@ -11,7 +12,7 @@ actual fun getWindowSize(): WindowSize {
val density = LocalDensity.current.density
val width = screenBounds.useContents { size.width } * density
val height = screenBounds.useContents { size.height } * density
return WindowSize(width.toInt(), height.toInt())
return WindowSize(width.roundToInt(), height.roundToInt())
}

actual fun platform(): Platform = Platform.IOS
7 changes: 6 additions & 1 deletion miuix/src/wasmJsMain/kotlin/expectUtils.wasmJs.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalDensity
import kotlinx.browser.window
import kotlin.math.roundToInt

@Composable
actual fun getWindowSize(): WindowSize {
return WindowSize(window.innerWidth, window.innerHeight)
val density = LocalDensity.current.density
val width = window.innerWidth * density
val height = window.innerHeight * density
return WindowSize(width.roundToInt(), height.roundToInt())
}

actual fun platform(): Platform = Platform.WasmJs

0 comments on commit a59e99e

Please sign in to comment.