File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
composeApp/src/wasmJsMain/kotlin/com/krossovochkin/chesskt Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 11package com.krossovochkin.chesskt
22
3+ import androidx.compose.runtime.*
4+ import androidx.compose.material.Text
35import androidx.compose.ui.ExperimentalComposeUiApi
46import androidx.compose.ui.window.ComposeViewport
57import kotlinx.browser.document
6- import kotlin.math.min
78import kotlinx.browser.window
9+ import kotlin.math.min
810import org.jetbrains.compose.resources.ExperimentalResourceApi
11+ import org.w3c.dom.HTMLElement
912
1013@OptIn(ExperimentalComposeUiApi ::class , ExperimentalResourceApi ::class )
1114fun main () {
1215 ComposeViewport (document.body!! ) {
13- App (screenSizePx = min(window.innerWidth, window.innerHeight))
16+ var size by remember { mutableStateOf<Int ?>(null ) }
17+
18+ LaunchedEffect (Unit ) {
19+ size = getContainerSize()
20+ }
21+
22+ if (size != null ) {
23+ App (screenSizePx = size!! )
24+ } else {
25+ Text (" Loading..." )
26+ }
27+ }
28+ }
29+
30+ private fun getContainerSize (): Int {
31+ val iframe = window.asDynamic().frameElement as ? HTMLElement
32+ return if (iframe != null ) {
33+ min(iframe.offsetWidth, iframe.offsetHeight)
34+ } else {
35+ min(window.innerWidth, window.innerHeight)
1436 }
1537}
You can’t perform that action at this time.
0 commit comments