mirror of
https://github.com/exyte/Macaw.git
synced 2024-08-15 16:10:39 +03:00
Fix early layer freeing
This commit is contained in:
parent
f3b07a6385
commit
aea8c57c82
@ -22,7 +22,16 @@ enum AnimationType {
|
||||
|
||||
class BasicAnimation: Animation {
|
||||
|
||||
weak var node: Node?
|
||||
weak var node: Node? {
|
||||
didSet {
|
||||
node?.animations.append(self)
|
||||
if let group = node as? Group {
|
||||
for node in group.contents {
|
||||
node.animations.append(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
weak var nodeRenderer: NodeRenderer?
|
||||
var type = AnimationType.unknown
|
||||
let ID: String
|
||||
|
@ -284,6 +284,10 @@ class AnimationProducer {
|
||||
continue
|
||||
}
|
||||
|
||||
defer {
|
||||
renderer.sceneLayer?.setNeedsDisplay()
|
||||
}
|
||||
|
||||
let progress = currentDate.timeIntervalSince(animationDesc.startDate) / animation.duration + animation.pausedProgress
|
||||
|
||||
// Completion
|
||||
|
@ -157,6 +157,17 @@ class AnimationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
extension Node {
|
||||
|
||||
func isAnimating() -> Bool {
|
||||
return !animations.filter { $0.state() == AnimationState.running }.isEmpty
|
||||
}
|
||||
|
||||
func needsLayer() -> Bool {
|
||||
return !animations.filter { $0.state() == AnimationState.running || $0.state() == AnimationState.initial }.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
extension NodeRenderer {
|
||||
|
||||
func isAnimating() -> Bool {
|
||||
@ -166,7 +177,7 @@ extension NodeRenderer {
|
||||
func freeLayer() {
|
||||
|
||||
let nodeRenderer = self
|
||||
guard let layer = nodeRenderer.layer else {
|
||||
guard let layer = nodeRenderer.layer, !node.needsLayer() else {
|
||||
return
|
||||
}
|
||||
nodeRenderer.layer = nil
|
||||
|
@ -34,8 +34,6 @@ func addOpacityAnimation(_ animation: BasicAnimation, _ context: AnimationContex
|
||||
|
||||
generatedAnimation.completion = { finished in
|
||||
|
||||
renderer.freeLayer()
|
||||
|
||||
if animation.paused {
|
||||
animation.pausedProgress += animation.progress
|
||||
node.opacityVar.value = opacityAnimation.getVFunc()(animation.pausedProgress)
|
||||
@ -49,6 +47,8 @@ func addOpacityAnimation(_ animation: BasicAnimation, _ context: AnimationContex
|
||||
node.opacityVar.value = opacityAnimation.getVFunc()(1.0)
|
||||
}
|
||||
|
||||
renderer.freeLayer()
|
||||
|
||||
if !animation.cycled &&
|
||||
!animation.manualStop &&
|
||||
!animation.paused {
|
||||
|
@ -38,6 +38,8 @@ open class Node: Drawable {
|
||||
set(val) { effectVar.value = val }
|
||||
}
|
||||
|
||||
var animations: [BasicAnimation] = []
|
||||
|
||||
// MARK: - Searching
|
||||
public func nodeBy(tag: String) -> Node? {
|
||||
if self.tag.contains(tag) {
|
||||
|
@ -76,9 +76,9 @@ class NodeRenderer {
|
||||
self.parentRenderer = parentRenderer
|
||||
|
||||
onNodeChange = { [weak view] in
|
||||
// if self.isAnimating() {
|
||||
// return
|
||||
// }
|
||||
if node.isAnimating() {
|
||||
return
|
||||
}
|
||||
|
||||
view?.setNeedsDisplay()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user