-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
.idea/runConfigurations/browser.xml → .idea/runConfigurations/browserJs.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
25 changes: 25 additions & 0 deletions
25
app/src/wasmJsMain/kotlin/io/github/xxfast/decompose/router/app/Application.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,25 @@ | ||
package io.github.xxfast.decompose.router.app | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.window.CanvasBasedWindow | ||
import io.github.xxfast.decompose.router.LocalRouterContext | ||
import io.github.xxfast.decompose.router.RouterContext | ||
import io.github.xxfast.decompose.router.screens.HomeScreen | ||
import io.github.xxfast.decompose.router.defaultRouterContext | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
fun main() { | ||
val rootRouterContext: RouterContext = defaultRouterContext() | ||
|
||
CanvasBasedWindow(canvasElementId = "ComposeTarget") { | ||
CompositionLocalProvider( | ||
LocalRouterContext provides rootRouterContext, | ||
) { | ||
MaterialTheme { | ||
HomeScreen() | ||
} | ||
} | ||
} | ||
} |
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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>App</title> | ||
<script src="skiko.js"></script> | ||
<link href="styles.css" rel="stylesheet" type="text/css"/> | ||
</head> | ||
<body> | ||
<div id="ComposeTargetContainer"> | ||
<canvas id="ComposeTarget"></canvas> | ||
<script src="app.js"></script> | ||
</div> | ||
</body> | ||
</html> |
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,14 @@ | ||
html, body { | ||
height: 100%; | ||
margin: 0px; | ||
padding: 0px; | ||
} | ||
|
||
canvas { | ||
width: 100vw; | ||
height: 100vh; | ||
display: block; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
...se-router/src/wasmJsMain/kotlin/io/github/xxfast/decompose/router/DefaultRouterContext.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,27 @@ | ||
package io.github.xxfast.decompose.router | ||
|
||
import com.arkivanov.essenty.backhandler.BackDispatcher | ||
import com.arkivanov.essenty.lifecycle.LifecycleRegistry | ||
import com.arkivanov.essenty.lifecycle.resume | ||
import com.arkivanov.essenty.lifecycle.stop | ||
import kotlinx.browser.document | ||
import org.w3c.dom.Document | ||
|
||
fun defaultRouterContext(): RouterContext { | ||
val backDispatcher = BackDispatcher() | ||
val lifecycle = LifecycleRegistry() | ||
lifecycle.attachToDocument() | ||
return RouterContext(lifecycle = lifecycle, backHandler = backDispatcher) | ||
} | ||
|
||
// Attaches the LifecycleRegistry to the document | ||
private fun LifecycleRegistry.attachToDocument() { | ||
fun onVisibilityChanged() = if (visibilityState(document) == "visible") resume() else stop() | ||
onVisibilityChanged() | ||
document.addEventListener(type = "visibilitychange", callback = { onVisibilityChanged() }) | ||
} | ||
|
||
// Workaround for Document#visibilityState not available in Wasm | ||
// From https://github.com/arkivanov/Minesweeper/blob/8270ffb0c75bf032b6d4da673c0bb2b01c9496ec/composeApp/src/wasmJsMain/kotlin/Main.kt#L47 | ||
@JsFun("(document) => document.visibilityState") | ||
private external fun visibilityState(document: Document): String |
7 changes: 7 additions & 0 deletions
7
decompose-router/src/wasmJsMain/kotlin/io/github/xxfast/decompose/router/Key.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 io.github.xxfast.decompose.router | ||
|
||
import kotlin.reflect.KClass | ||
|
||
// TODO: Given that we don't have tree-shaking on js - yet, should be safe to use simpleName here | ||
actual val KClass<*>.key: String get() = | ||
requireNotNull(simpleName) { "Unable to use name of $this as the default key"} |
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