Skip to content

Commit

Permalink
cfw: Update ComposeWindow implement resizing strategy (#692)
Browse files Browse the repository at this point in the history
Updated the resize function in ComposeWindow.js.kt to avoid multiple event listeners being applied on every resize event. Implemented via cloning the old canvas and replacing it with the new one. This is a workaround solution and a better strategy to fix this in skiko will be considered in the future.
  • Loading branch information
eymar authored Jul 19, 2023
1 parent 429cfb8 commit 276cd47
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ internal actual class ComposeWindow(val canvasId: String) {
input = jsTextInputService.input
)

val canvas = document.getElementById(canvasId) as HTMLCanvasElement
var canvas = document.getElementById(canvasId) as HTMLCanvasElement
private set

init {
layer.layer.attachTo(canvas)
Expand All @@ -80,6 +81,12 @@ internal actual class ComposeWindow(val canvasId: String) {
}

fun resize(newSize: IntSize) {
// TODO: avoid node cloning. We clone now to workaround multiple event listeners being applied on every resize event.
// Consider fixing in skiko.
val oldCanvas = canvas
canvas = oldCanvas.cloneNode(true) as HTMLCanvasElement
oldCanvas.parentElement!!.replaceChild(canvas, oldCanvas)

canvas.width = newSize.width
canvas.height = newSize.height
layer.layer.attachTo(canvas)
Expand Down

0 comments on commit 276cd47

Please sign in to comment.