Skip to content

Commit

Permalink
Ensure onWasmReady is properly defined for Kotlin/Wasm target
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartosdev committed Apr 3, 2024
1 parent fabda97 commit 18e5750
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.components.experimental.puzzle15.ui.Puzzle15Ui
import org.jetbrains.skiko.wasm.onWasmReady

external fun onWasmReady(onReady: () -> Unit)

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private const val CANVAS_ELEMENT_ID = "ComposeTarget" // Hardwired into ComposeW
/**
* A Skiko/Canvas-based top-level window using the browser's entire viewport. Supports resizing.
*/
@Composable
@Suppress("FunctionNaming")
fun BrowserViewportWindow(
title: String = "Untitled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private const val CANVAS_ELEMENT_ID = "ComposeTarget" // Hardwired into ComposeW
/**
* A Skiko/Canvas-based top-level window using the browser's entire viewport. Supports resizing.
*/
@Composable
@Suppress("FunctionNaming")
fun BrowserViewportWindow(
title: String = "Untitled",
Expand Down Expand Up @@ -61,7 +60,7 @@ fun BrowserViewportWindow(
}

ComposeWindow(canvasId = "Appyx", content = content).apply {
window.addEventListener("resize", {
window.addEventListener("resize") {
canvas.fillViewportSize()
layer.layer.attachTo(canvas)
layer.layer.needRedraw()
Expand All @@ -70,7 +69,7 @@ fun BrowserViewportWindow(
(canvas.width / scale * density.density).toInt(),
(canvas.height / scale * density.density).toInt()
)
})
}

// WORKAROUND: ComposeWindow does not implement `setTitle(title)`
val htmlTitleElement = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import com.bumble.appyx.components.internal.testdrive.ui.md_light_green_500
import com.bumble.appyx.components.internal.testdrive.ui.md_lime_500
import com.bumble.appyx.components.internal.testdrive.ui.md_pink_500
import com.bumble.appyx.components.internal.testdrive.ui.md_teal_500
import org.jetbrains.skiko.wasm.onWasmReady

external fun onWasmReady(onReady: () -> Unit)

val manatee = Color(0xFF8D99AE)
val silver_sand = Color(0xFFBDC6D1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.demos.common.color_dark
import org.jetbrains.skiko.wasm.onWasmReady

external fun onWasmReady(onReady: () -> Unit)

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.CanvasBasedWindow
import com.bumble.appyx.demos.sandbox.navigation.node.container.MainNavNode
import com.bumble.appyx.demos.sandbox.navigation.ui.AppyxSampleAppTheme
import com.bumble.appyx.navigation.integration.BrowserViewportWindow
import com.bumble.appyx.navigation.integration.ScreenSize
import com.bumble.appyx.navigation.integration.WebNodeHost
import kotlinx.coroutines.CoroutineScope
Expand All @@ -35,11 +35,10 @@ import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import org.jetbrains.skiko.wasm.onWasmReady

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
val events: Channel<Unit> = Channel()
onWasmReady {
CanvasBasedWindow("Navigation Demo") {
BrowserViewportWindow("Navigation Demo") {
val requester = remember { FocusRequester() }
var hasFocus by remember { mutableStateOf(false) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import org.jetbrains.skiko.wasm.onWasmReady

external fun onWasmReady(onReady: () -> Unit)

fun main() {
val events: Channel<Unit> = Channel()
Expand Down
2 changes: 1 addition & 1 deletion documentation/navigation/multiplatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fun main() = application {
fun main() {
val events: Channel<Unit> = Channel()
onWasmReady {
CanvasBasedWindow("Your app") {
BrowserViewportWindow("Your app") {
val requester = remember { FocusRequester() }
var hasFocus by remember { mutableStateOf(false) }
var screenSize by remember { mutableStateOf(ScreenSize(0.dp, 0.dp)) }
Expand Down

0 comments on commit 18e5750

Please sign in to comment.