1
1
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:
Alisa Mylnikova 2019-05-29 15:04:25 +07:00
parent f3b07a6385
commit aea8c57c82
6 changed files with 33 additions and 7 deletions

View File

@ -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

View File

@ -284,6 +284,10 @@ class AnimationProducer {
continue
}
defer {
renderer.sceneLayer?.setNeedsDisplay()
}
let progress = currentDate.timeIntervalSince(animationDesc.startDate) / animation.duration + animation.pausedProgress
// Completion

View File

@ -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

View File

@ -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 {

View File

@ -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) {

View File

@ -76,9 +76,9 @@ class NodeRenderer {
self.parentRenderer = parentRenderer
onNodeChange = { [weak view] in
// if self.isAnimating() {
// return
// }
if node.isAnimating() {
return
}
view?.setNeedsDisplay()
}