Skip to content

Commit

Permalink
fix: ios spa多次创建导致canvas白屏。Closed #630
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Mar 18, 2020
1 parent 1ad16fa commit ea3f84f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/graphic/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ class Canvas extends EventEmit {
if (this.get('destroyed')) {
return;
}
// 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
// https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
// https://github.com/antvis/F2/issues/630
const el = this.get('el');
el.width = 0;
el.height = 0;
this.clear();
this._attrs = {};
this.set('destroyed', true);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/graphic/canvas-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('Canvas', function() {

it('clear canvas', function() {
const canvas = new Canvas({
el: 'canvas',
el: dom,
width: 500,
height: 500,
pixelRatio: 1
Expand All @@ -145,6 +145,8 @@ describe('Canvas', function() {
canvas.clear();
expect(canvas.getChildren()).to.be.an('array').that.is.empty;
canvas.destroy();
expect(dom.width).to.equal(0);
expect(dom.height).to.equal(0);
expect(canvas.isDestroyed()).to.be.true;
document.body.removeChild(dom);
});
Expand Down

0 comments on commit ea3f84f

Please sign in to comment.