mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Replace top renderers with top layers
This commit is contained in:
parent
c1cebea871
commit
c7bba3438b
@ -18,7 +18,7 @@ class AnimationProducer {
|
||||
let animation: ContentsAnimation
|
||||
let layer: CALayer
|
||||
weak var cache: AnimationCache?
|
||||
let topRenderers: [WeakThing<NodeRenderer>]
|
||||
let topLayers: [ShapeLayer]
|
||||
let startDate: Date
|
||||
let finishDate: Date
|
||||
let completion: (() -> Void)?
|
||||
@ -272,10 +272,13 @@ class AnimationProducer {
|
||||
}
|
||||
let bottomRenderer = animationRenderers.min { $0.zPosition < $1.zPosition }
|
||||
|
||||
var topLayers = [ShapeLayer]()
|
||||
var topRenderers = [WeakThing<NodeRenderer>]()
|
||||
if let bottomRenderer = bottomRenderer, let allRenderers = allRenderers {
|
||||
for renderer in allRenderers where !(renderer is GroupRenderer) && renderer.zPosition > bottomRenderer.zPosition {
|
||||
topRenderers.append(WeakThing(renderer))
|
||||
if let layer = cache?.layerForNodeRenderer(renderer, context, animation: contentsAnimation) {
|
||||
topLayers.append(layer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +286,7 @@ class AnimationProducer {
|
||||
animation: contentsAnimation,
|
||||
layer: layer,
|
||||
cache: cache,
|
||||
topRenderers: topRenderers,
|
||||
topLayers: topLayers,
|
||||
startDate: Date(),
|
||||
finishDate: Date(timeInterval: contentsAnimation.duration, since: startDate),
|
||||
completion: completion
|
||||
@ -340,6 +343,9 @@ class AnimationProducer {
|
||||
contentsAnimations.remove(at: count - 1 - index)
|
||||
animationDesc.cache?.freeLayer(renderer)
|
||||
animationDesc.completion?()
|
||||
for layer in animationDesc.topLayers {
|
||||
animationDesc.cache?.freeLayer(layer: layer)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@ -362,12 +368,9 @@ class AnimationProducer {
|
||||
}
|
||||
}
|
||||
|
||||
for weakRenderer in animationDesc.topRenderers {
|
||||
if let renderer = weakRenderer.value {
|
||||
let layer = animationDesc.cache?.layerForNodeRenderer(renderer, context, animation: animationDesc.animation)
|
||||
layer?.setNeedsDisplay()
|
||||
layer?.displayIfNeeded()
|
||||
}
|
||||
for layer in animationDesc.topLayers {
|
||||
layer.setNeedsDisplay()
|
||||
layer.displayIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +140,31 @@ class AnimationCache {
|
||||
layer.removeFromSuperlayer()
|
||||
}
|
||||
|
||||
func freeLayer(layer: ShapeLayer) {
|
||||
var cached: CachedLayer?
|
||||
var renderer: NodeRenderer?
|
||||
layerCache.forEach { key, value in
|
||||
if value.layer === layer {
|
||||
cached = value
|
||||
renderer = key
|
||||
}
|
||||
}
|
||||
guard let cachedLayer = cached, let nodeRenderer = renderer else {
|
||||
return
|
||||
}
|
||||
|
||||
cachedLayer.linksCounter -= 1
|
||||
|
||||
if cachedLayer.linksCounter != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
let layer = cachedLayer.layer
|
||||
layerCache.removeValue(forKey: nodeRenderer)
|
||||
sceneLayer?.setNeedsDisplay()
|
||||
layer.removeFromSuperlayer()
|
||||
}
|
||||
|
||||
func freeLayer(_ renderer: NodeRenderer) {
|
||||
guard let cachedLayer = layerCache[renderer] else {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user