@@ -4,19 +4,7 @@ let animationProducer = AnimationProducer()
44
55class AnimationProducer {
66
7-
87 var storedAnimations = [ Node: BasicAnimation] ( )
9- var displayLink : CADisplayLink ?
10-
11- struct ContentAnimationDesc {
12- let animation : ContentsAnimation
13- let layer : CALayer
14- let cache : AnimationCache
15- let startDate : Date
16- let finishDate : Date
17- }
18-
19- var contentsAnimations = [ ContentAnimationDesc] ( )
208
219 func addAnimation( _ animation: BasicAnimation , withoutDelay: Bool = false ) {
2210
@@ -67,14 +55,10 @@ class AnimationProducer {
6755 addAnimationSequence ( animation)
6856 case . combine:
6957 addCombineAnimation ( animation)
70- case . contents:
71- addContentsAnimation ( animation, cache: cache)
7258 case . empty:
7359 executeCompletion ( animation)
7460 }
7561 }
76-
77- // MARK: - Sequence animation
7862 fileprivate func addAnimationSequence( _ animationSequnce: Animation ) {
7963 guard let sequence = animationSequnce as? AnimationSequence else {
8064 return
@@ -127,7 +111,6 @@ class AnimationProducer {
127111 }
128112 }
129113
130- // MARK: - Combine animation
131114 fileprivate func addCombineAnimation( _ combineAnimation: Animation ) {
132115 guard let combine = combineAnimation as? CombineAnimation else {
133116 return
@@ -194,12 +177,10 @@ class AnimationProducer {
194177 }
195178 }
196179
197- // MARK: - Empty Animation
198180 fileprivate func executeCompletion( _ emptyAnimation: BasicAnimation ) {
199181 emptyAnimation. completion ? ( )
200182 }
201-
202- // MARK: - Stored animation
183+
203184 func addStoredAnimations( _ node: Node ) {
204185 if let animation = storedAnimations [ node] {
205186 addAnimation ( animation)
@@ -214,63 +195,4 @@ class AnimationProducer {
214195 addStoredAnimations ( child)
215196 }
216197 }
217-
218- // MARK: - Contents animation
219-
220- func addContentsAnimation( _ animation: BasicAnimation , cache: AnimationCache ) {
221- guard let contentsAnimation = animation as? ContentsAnimation else {
222- return
223- }
224-
225- guard let node = contentsAnimation. node else {
226- return
227- }
228-
229- let startDate = Date ( timeInterval: contentsAnimation. delay, since: Date ( ) )
230-
231- let animationDesc = ContentAnimationDesc (
232- animation: contentsAnimation,
233- layer: cache. layerForNode ( node, animation: contentsAnimation) ,
234- cache: cache,
235- startDate: Date ( ) ,
236- finishDate: Date ( timeInterval: contentsAnimation. duration, since: startDate) )
237-
238- contentsAnimations. append ( animationDesc)
239-
240- if displayLink == . none {
241- displayLink = CADisplayLink ( target: self , selector: #selector( updateContentAnimations) )
242- displayLink? . frameInterval = 1
243- displayLink? . add ( to: RunLoop . current, forMode: RunLoopMode . defaultRunLoopMode)
244- }
245-
246-
247- }
248-
249- @objc func updateContentAnimations( ) {
250- if contentsAnimations. count == 0 {
251- displayLink? . invalidate ( )
252- displayLink = . none
253- }
254-
255- let currentDate = Date ( )
256- for (index, animationDesc) in contentsAnimations. enumerated ( ) {
257-
258- let animation = animationDesc. animation
259- guard let node = animation. node else {
260- continue
261- }
262-
263- let progress = currentDate. timeIntervalSince ( animationDesc. startDate) / animation. duration
264- if progress >= 1.0 {
265- animation. completion ? ( )
266- contentsAnimations. remove ( at: index)
267- animationDesc. cache. freeLayer ( node)
268- continue
269- }
270-
271- animation. getVFunc ( ) ( progress)
272- animationDesc. layer. setNeedsDisplay ( )
273- animation. onProgressUpdate ? ( progress)
274- }
275- }
276198}
0 commit comments