Skip to content

Commit

Permalink
wasmjs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhirkevich committed Apr 7, 2024
1 parent 2055d7a commit 67d0475
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions example/shared/src/wasmJsMain/kotlin/WasmApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ import org.w3c.dom.Document
*/

@OptIn(ExperimentalComposeUiApi::class)
fun Wasm() {
fun WasmApp() {

val lifecycle = LifecycleRegistry()

val root = DefaultRootComponent(
DefaultComponentContext(lifecycle = lifecycle),
)

lifecycle.attachToDocument()


CanvasBasedWindow {

var mobile by remember {
Expand Down Expand Up @@ -101,19 +98,4 @@ fun Wasm() {
}
}

private fun LifecycleRegistry.attachToDocument() {
fun onVisibilityChanged() {
if (document.visibilityState == "visible") {
resume()
} else {
stop()
}
}

onVisibilityChanged()

document.addEventListener(type = "visibilitychange", callback = { onVisibilityChanged() })
}

private val Document.visibilityState: String
get() = asDynamic().visibilityState.unsafeCast<String>()

0 comments on commit 67d0475

Please sign in to comment.