mirror of
				https://github.com/konvajs/konva.git
				synced 2025-11-01 01:06:39 +08:00 
			
		
		
		
	fix cache with invisble shapes
This commit is contained in:
		| @@ -198,7 +198,9 @@ export class Shape< | ||||
|   } | ||||
|  | ||||
|   getContext() { | ||||
|     Util.warn('shape.getContext() method is deprecated. Please don not use it.'); | ||||
|     Util.warn( | ||||
|       'shape.getContext() method is deprecated. Please don not use it.' | ||||
|     ); | ||||
|     return this.getLayer().getContext(); | ||||
|   } | ||||
|   getCanvas() { | ||||
| @@ -575,11 +577,10 @@ export class Shape< | ||||
|       bufferCanvas, | ||||
|       bufferContext; | ||||
|  | ||||
|     var caching = canvas.isCache; | ||||
|     var skipBuffer = canvas.isCache; | ||||
|     var cachingSelf = top === this; | ||||
|  | ||||
|     if (!this.isVisible() && !caching) { | ||||
|     if (!this.isVisible() && !cachingSelf) { | ||||
|       return this; | ||||
|     } | ||||
|     // if node is cached we just need to draw from cache | ||||
|   | ||||
| @@ -902,6 +902,42 @@ describe('Caching', function () { | ||||
|     assert.equal(stage.getIntersection({ x: 150, y: 100 }), rect); | ||||
|   }); | ||||
|  | ||||
|   it('check cache for invisible shape', function () { | ||||
|     var stage = addStage(); | ||||
|  | ||||
|     var layer = new Konva.Layer({ | ||||
|       // visible: false, | ||||
|     }); | ||||
|  | ||||
|     var group = new Konva.Group(); | ||||
|     layer.add(group); | ||||
|  | ||||
|     group.add( | ||||
|       new Konva.Rect({ | ||||
|         x: 50, | ||||
|         y: 50, | ||||
|         width: 100, | ||||
|         height: 100, | ||||
|         fill: 'red', | ||||
|       }) | ||||
|     ); | ||||
|     var rect = new Konva.Rect({ | ||||
|       x: 0, | ||||
|       y: 0, | ||||
|       width: 100, | ||||
|       height: 100, | ||||
|       fill: 'green', | ||||
|       visible: false, | ||||
|     }); | ||||
|     group.add(rect); | ||||
|  | ||||
|     stage.add(layer); | ||||
|  | ||||
|     group.cache(); | ||||
|     layer.draw(); | ||||
|     cloneAndCompareLayer(layer); | ||||
|   }); | ||||
|  | ||||
|   it('even if parent is not listening cache and hit should be created', function () { | ||||
|     var stage = addStage(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Anton Lavrenov
					Anton Lavrenov