NativeScript / canvas

Apache License 2.0
88 stars 18 forks source link

[bug] Canvas content gets reset if app draws with delay #93

Closed CatchABus closed 2 months ago

CatchABus commented 1 year ago

It seems that if I draw something on canvas using a timeout, the previous drawing will be erased. Seems to occur on android and ios (devices only)

Samples to test:

This works


export function onContextReady(args) {
  var canvas = args.object;
  var ctx = canvas.getContext("2d");
  ctx.rect(50, 20, 200, 120);
  ctx.stroke();
  ctx.fillStyle = "red";
  ctx.fillRect(0, 0, 150, 100);
}

Screenshot from 2022-11-17 12-38-49

This is with timeout. It will erase first shape and draw red rectangle alone

export function onContextReady(args) {
  var canvas = args.object;
  var ctx = canvas.getContext("2d");
  ctx.rect(50, 20, 200, 120);
  ctx.stroke();
  ctx.fillStyle = "red";
  setTimeout(() => ctx.fillRect(0, 0, 150, 100), 2000);
}

Screenshot from 2022-11-17 12-39-05

triniwiz commented 2 months ago

Fixed in https://github.com/NativeScript/canvas/commit/9a5723f7f7b6aa555e8a3f020ffc8bfc5753ad50