Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
Move CAAnimation performer code to private/ sub-directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Verkoeyen committed Oct 3, 2016
1 parent c69478d commit 9300ad6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
32 changes: 0 additions & 32 deletions src/CAAnimationPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,3 @@ extension CAAnimation: Plan {
return CoreAnimationPerformer.self
}
}

/** A light-weight Core Animation Material Motion performer. */
class CoreAnimationPerformer: NSObject, PlanPerforming, ContinuousPerforming {
let target: CALayer
required init(target: Any) {
if let view = target as? UIView {
self.target = view.layer
} else {
self.target = target as! CALayer
}
}

func add(plan: Plan) {
let animation = plan as! CAAnimation

CATransaction.begin()

guard let token = tokenGenerator.generate() else { return }
CATransaction.setCompletionBlock {
token.terminate()
}

target.add(animation, forKey: nil)

CATransaction.commit()
}

var tokenGenerator: IsActiveTokenGenerating!
func set(isActiveTokenGenerator: IsActiveTokenGenerating) {
tokenGenerator = isActiveTokenGenerator
}
}
49 changes: 49 additions & 0 deletions src/private/CAAnimationPerformer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import UIKit
import MaterialMotionRuntime

class CoreAnimationPerformer: NSObject, PlanPerforming, ContinuousPerforming {
let target: CALayer
required init(target: Any) {
if let view = target as? UIView {
self.target = view.layer
} else {
self.target = target as! CALayer
}
}

func add(plan: Plan) {
let animation = plan as! CAAnimation

CATransaction.begin()

guard let token = tokenGenerator.generate() else { return }
CATransaction.setCompletionBlock {
token.terminate()
}

target.add(animation, forKey: nil)

CATransaction.commit()
}

var tokenGenerator: IsActiveTokenGenerating!
func set(isActiveTokenGenerator: IsActiveTokenGenerating) {
tokenGenerator = isActiveTokenGenerator
}
}

0 comments on commit 9300ad6

Please sign in to comment.