From bac14c1e85c024fac6acd235d4d52b2f103e49fe Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Tue, 17 Mar 2020 17:16:18 +0700 Subject: [PATCH] Fixes for examples --- Source/animation/AnimationImpl.swift | 11 ++++++----- Source/animation/AnimationProducer.swift | 4 ++-- Source/animation/types/AnimationSequence.swift | 12 ++++-------- .../CombinationAnimationGenerator.swift | 2 ++ .../animation_generators/MorphingGenerator.swift | 1 + .../animation_generators/OpacityGenerator.swift | 10 ++++++++++ .../animation_generators/TransformGenerator.swift | 10 ++++++++++ 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Source/animation/AnimationImpl.swift b/Source/animation/AnimationImpl.swift index 0b79032e..a6fca1ab 100644 --- a/Source/animation/AnimationImpl.swift +++ b/Source/animation/AnimationImpl.swift @@ -24,11 +24,8 @@ class BasicAnimation: Animation { weak var node: Node? { didSet { - node?.animations.append(self) - if let group = node as? Group { - for node in group.contents { - node.animations.append(self) - } + if !(self is CombineAnimation || self is AnimationSequence || self is EmptyAnimation) { + node?.animations.append(self) } } } @@ -104,6 +101,8 @@ class BasicAnimation: Animation { } removeFunc?() + node?.animations.removeAll { $0 === self } + nodeRenderer?.freeLayer() } override open func pause() { @@ -115,6 +114,8 @@ class BasicAnimation: Animation { } removeFunc?() + node?.animations.removeAll { $0 === self } + nodeRenderer?.freeLayer() } override func state() -> AnimationState { diff --git a/Source/animation/AnimationProducer.swift b/Source/animation/AnimationProducer.swift index b6c8887d..85728e26 100644 --- a/Source/animation/AnimationProducer.swift +++ b/Source/animation/AnimationProducer.swift @@ -143,9 +143,9 @@ class AnimationProducer { } // MARK: - Sequence animation - func addAnimationSequence(_ animationSequnce: Animation, + func addAnimationSequence(_ animationSequence: Animation, _ context: AnimationContext) { - guard let sequence = animationSequnce as? AnimationSequence else { + guard let sequence = animationSequence as? AnimationSequence else { return } diff --git a/Source/animation/types/AnimationSequence.swift b/Source/animation/types/AnimationSequence.swift index abb711e7..951e0bac 100644 --- a/Source/animation/types/AnimationSequence.swift +++ b/Source/animation/types/AnimationSequence.swift @@ -27,21 +27,17 @@ internal class AnimationSequence: BasicAnimation { open override func stop() { super.stop() - guard let active = animations.first(where: { $0.isActive() }) else { - return + animations.forEach { animation in + animation.stop() } - - active.stop() } open override func pause() { super.pause() - guard let active = animations.first(where: { $0.isActive() }) else { - return + animations.forEach { animation in + animation.pause() } - - active.pause() } open override func play() { diff --git a/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift b/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift index ee38fa7d..d600b4a5 100644 --- a/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift +++ b/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift @@ -116,6 +116,7 @@ extension AnimationProducer { func addCombineAnimation(_ combineAnimation: Animation, _ context: AnimationContext) { guard let combine = combineAnimation as? CombineAnimation, let renderer = combine.nodeRenderer, + let node = combine.node, let view = renderer.view else { return } @@ -176,6 +177,7 @@ extension AnimationProducer { } combine.removeFunc = { + node.animations.removeAll { $0 === combine } animations.forEach { animation in animation.removeFunc?() } diff --git a/Source/animation/types/animation_generators/MorphingGenerator.swift b/Source/animation/types/animation_generators/MorphingGenerator.swift index 09d54277..b077c26b 100644 --- a/Source/animation/types/animation_generators/MorphingGenerator.swift +++ b/Source/animation/types/animation_generators/MorphingGenerator.swift @@ -94,6 +94,7 @@ func addMorphingAnimation(_ animation: BasicAnimation, _ context: AnimationConte let animationId = animation.ID layer.add(generatedAnimation, forKey: animationId) animation.removeFunc = { [weak layer] in + shape.animations.removeAll { $0 === animation } layer?.removeAnimation(forKey: animationId) } diff --git a/Source/animation/types/animation_generators/OpacityGenerator.swift b/Source/animation/types/animation_generators/OpacityGenerator.swift index 9bcdde1b..dc58b087 100644 --- a/Source/animation/types/animation_generators/OpacityGenerator.swift +++ b/Source/animation/types/animation_generators/OpacityGenerator.swift @@ -47,6 +47,15 @@ func addOpacityAnimation(_ animation: BasicAnimation, _ context: AnimationContex node.opacityVar.value = opacityAnimation.getVFunc()(1.0) } + CATransaction.begin() + CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) + renderer.layer?.animationLayer.opacity = Float(node.opacity) + CATransaction.commit() + + if !animation.paused { + animation.removeFunc?() + } + renderer.freeLayer() if !animation.cycled && @@ -62,6 +71,7 @@ func addOpacityAnimation(_ animation: BasicAnimation, _ context: AnimationContex let animationId = animation.ID layer.add(generatedAnimation, forKey: animationId) animation.removeFunc = { [weak layer] in + node.animations.removeAll { $0 === animation } layer?.removeAnimation(forKey: animationId) } diff --git a/Source/animation/types/animation_generators/TransformGenerator.swift b/Source/animation/types/animation_generators/TransformGenerator.swift index bf91385c..5e45377d 100644 --- a/Source/animation/types/animation_generators/TransformGenerator.swift +++ b/Source/animation/types/animation_generators/TransformGenerator.swift @@ -54,6 +54,15 @@ func addTransformAnimation(_ animation: BasicAnimation, _ context: AnimationCont node.placeVar.value = transformAnimation.getVFunc()(1.0) } + CATransaction.begin() + CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) + renderer.layer?.animationLayer.transform = CATransform3DMakeAffineTransform(node.place.toCG()) + CATransaction.commit() + + if !animation.paused { + animation.removeFunc?() + } + renderer.freeLayer() if !animation.cycled && @@ -68,6 +77,7 @@ func addTransformAnimation(_ animation: BasicAnimation, _ context: AnimationCont let animationId = animation.ID layer.add(generatedAnimation, forKey: animationId) animation.removeFunc = { [weak layer] in + node.animations.removeAll { $0 === animation } layer?.removeAnimation(forKey: animationId) }