Browse Source

Dispose skiko when it not used anymore

with_mpp_example
Shagen Ogandzhanian 3 years ago
parent
commit
729bcac815
  1. 2
      examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt
  2. 10
      web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt

2
examples/web-skia/src/jsMain/kotlin/com/sample/Main.kt

@ -377,8 +377,6 @@ fun SomeCanvas() {
)
}
Text(text = "Xxx")
Canvas(
modifier = Modifier
.size(400.dp)

10
web/core/src/jsMain/kotlin/org/jetbrains/compose/skiko/skiko.kt

@ -14,9 +14,15 @@ import org.w3c.dom.HTMLCanvasElement
@Composable
fun ElementScope<HTMLCanvasElement>.skiko(block: @Composable () -> Unit) {
DomSideEffect { canvas ->
var skikoCanvas: ComposeCanvas? = null
onWasmReady {
val skikoCanvas = ComposeCanvas(canvas)
skikoCanvas.setContent(block)
skikoCanvas = ComposeCanvas(canvas)
skikoCanvas?.setContent(block)
}
onDispose {
skikoCanvas?.dispose()
}
}
}
Loading…
Cancel
Save