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( Canvas(
modifier = Modifier modifier = Modifier
.size(400.dp) .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 @Composable
fun ElementScope<HTMLCanvasElement>.skiko(block: @Composable () -> Unit) { fun ElementScope<HTMLCanvasElement>.skiko(block: @Composable () -> Unit) {
DomSideEffect { canvas -> DomSideEffect { canvas ->
var skikoCanvas: ComposeCanvas? = null
onWasmReady { onWasmReady {
val skikoCanvas = ComposeCanvas(canvas) skikoCanvas = ComposeCanvas(canvas)
skikoCanvas.setContent(block) skikoCanvas?.setContent(block)
}
onDispose {
skikoCanvas?.dispose()
} }
} }
} }
Loading…
Cancel
Save