Commit 7e8a98ad by Daniel Dahan

master: moved Motion to Animation in favor of importing the Motion framework separately

parent a7fd4016
...@@ -84,9 +84,9 @@ public func AnimationTimingFunctionToValue(function: AnimationTimingFunction) -> ...@@ -84,9 +84,9 @@ public func AnimationTimingFunctionToValue(function: AnimationTimingFunction) ->
} }
} }
public typealias MotionDelayCancelBlock = (Bool) -> Void public typealias AnimationDelayCancelBlock = (Bool) -> Void
public struct Motion { public struct Animation {
/** /**
Executes a block of code after a time delay. Executes a block of code after a time delay.
- Parameter duration: An animation duration time. - Parameter duration: An animation duration time.
...@@ -95,15 +95,15 @@ public struct Motion { ...@@ -95,15 +95,15 @@ public struct Motion {
the animations have completed. the animations have completed.
*/ */
@discardableResult @discardableResult
public static func delay(time: TimeInterval, execute block: @escaping () -> Void) -> MotionDelayCancelBlock? { public static func delay(time: TimeInterval, execute block: @escaping () -> Void) -> AnimationDelayCancelBlock? {
func asyncAfter(completion: @escaping () -> Void) { func asyncAfter(completion: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion)
} }
var cancelable: MotionDelayCancelBlock? var cancelable: AnimationDelayCancelBlock?
let delayed: MotionDelayCancelBlock = { let delayed: AnimationDelayCancelBlock = {
if !$0 { if !$0 {
DispatchQueue.main.async(execute: block) DispatchQueue.main.async(execute: block)
} }
...@@ -121,10 +121,10 @@ public struct Motion { ...@@ -121,10 +121,10 @@ public struct Motion {
} }
/** /**
Cancels the delayed MotionDelayCancelBlock. Cancels the delayed AnimationDelayCancelBlock.
- Parameter delayed completion: An MotionDelayCancelBlock. - Parameter delayed completion: An AnimationDelayCancelBlock.
*/ */
public static func cancel(delayed completion: MotionDelayCancelBlock) { public static func cancel(delayed completion: AnimationDelayCancelBlock) {
completion(true) completion(true)
} }
......
...@@ -114,7 +114,7 @@ public struct Pulse { ...@@ -114,7 +114,7 @@ public struct Pulse {
let w = view.bounds.width let w = view.bounds.width
let h = view.bounds.height let h = view.bounds.height
Motion.disable(animations: { [ Animation.disable(animations: { [
n = .center == animation ? w < h ? w : h : w < h ? h : w, n = .center == animation ? w < h ? w : h : w < h ? h : w,
bounds = layer.bounds, bounds = layer.bounds,
animation = animation, animation = animation,
...@@ -143,17 +143,17 @@ public struct Pulse { ...@@ -143,17 +143,17 @@ public struct Pulse {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking: case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Motion.backgroundColor(color: color.withAlphaComponent(opacity / 2), duration: duration), forKey: nil) bLayer.add(Animation.backgroundColor(color: color.withAlphaComponent(opacity / 2), duration: duration), forKey: nil)
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Motion.scale(by: 1, duration: duration), forKey: nil) pLayer.add(Animation.scale(by: 1, duration: duration), forKey: nil)
default:break default:break
} }
Motion.delay(time: duration) { Animation.delay(time: duration) {
bLayer.setValue(true, forKey: "animated") bLayer.setValue(true, forKey: "animated")
} }
} }
...@@ -168,7 +168,7 @@ public struct Pulse { ...@@ -168,7 +168,7 @@ public struct Pulse {
return return
} }
Motion.delay(time: animated ? 0 : 0.15) { [animation = animation, color = color] in Animation.delay(time: animated ? 0 : 0.15) { [animation = animation, color = color] in
guard let pLayer = bLayer.sublayers?.first as? CAShapeLayer else { guard let pLayer = bLayer.sublayers?.first as? CAShapeLayer else {
return return
} }
...@@ -177,20 +177,20 @@ public struct Pulse { ...@@ -177,20 +177,20 @@ public struct Pulse {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking: case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Motion.backgroundColor(color: color.withAlphaComponent(0), duration: duration), forKey: nil) bLayer.add(Animation.backgroundColor(color: color.withAlphaComponent(0), duration: duration), forKey: nil)
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Motion.animate(group: [ pLayer.add(Animation.animate(group: [
Motion.scale(by: .center == animation ? 1 : 1.325), Animation.scale(by: .center == animation ? 1 : 1.325),
Motion.backgroundColor(color: color.withAlphaComponent(0)) Animation.backgroundColor(color: color.withAlphaComponent(0))
], duration: duration), forKey: nil) ], duration: duration), forKey: nil)
default:break default:break
} }
Motion.delay(time: duration) { Animation.delay(time: duration) {
pLayer.removeFromSuperlayer() pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer() bLayer.removeFromSuperlayer()
} }
......
...@@ -191,7 +191,7 @@ open class Button: UIButton, Pulseable { ...@@ -191,7 +191,7 @@ open class Button: UIButton, Pulseable {
let p = point ?? center let p = point ?? center
pulse.expandAnimation(point: p) pulse.expandAnimation(point: p)
Motion.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
self?.pulse.contractAnimation() self?.pulse.contractAnimation()
} }
} }
......
...@@ -243,7 +243,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable { ...@@ -243,7 +243,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
let p = point ?? center let p = point ?? center
pulse.expandAnimation(point: p) pulse.expandAnimation(point: p)
Motion.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
self?.pulse.contractAnimation() self?.pulse.contractAnimation()
} }
} }
......
...@@ -201,7 +201,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable { ...@@ -201,7 +201,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable {
let p = point ?? center let p = point ?? center
pulse.expandAnimation(point: p) pulse.expandAnimation(point: p)
Motion.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
self?.pulse.contractAnimation() self?.pulse.contractAnimation()
} }
} }
......
...@@ -335,7 +335,7 @@ extension CALayer { ...@@ -335,7 +335,7 @@ extension CALayer {
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
let a = Motion.shadowPath(to: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath) let a = Animation.shadowPath(to: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath)
a.fromValue = shadowPath a.fromValue = shadowPath
animate(animation: a) animate(animation: a)
} }
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(AnimationRotationMode)
public enum AnimationRotationMode: Int {
case `default`
case auto
case autoReverse
}
/**
Converts an AnimationRotationMode to a corresponding CAAnimationRotate key.
- Parameter mode: An AnimationRotationMode.
- Returns: An optional CAAnimationRotate key String.
*/
public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String? {
switch mode {
case .default:
return nil
case .auto:
return kCAAnimationRotateAuto
case .autoReverse:
return kCAAnimationRotateAutoReverse
}
}
extension Motion {
/**
Creates a CAKeyframeAnimation.
- Parameter bezierPath: A UIBezierPath.
- Parameter mode: An AnimationRotationMode.
- Parameter duration: An animation duration time.
- Returns: A CAKeyframeAnimation.
*/
public static func path(bezierPath: UIBezierPath, mode: AnimationRotationMode = .auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation = CAKeyframeAnimation()
animation.keyPath = AnimationKeyPath.position.rawValue
animation.path = bezierPath.cgPath
animation.rotationMode = AnimationRotationModeToValue(mode: mode)
if let v = duration {
animation.duration = v
}
return animation
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(AnimationTransition)
public enum AnimationTransition: Int {
case fade
case moveIn
case push
case reveal
}
@objc(AnimationTransitionDirection)
public enum AnimationTransitionDirection: Int {
case `default`
case right
case left
case top
case bottom
}
/**
Converts an AnimationTransition to a corresponding CATransition key.
- Parameter transition: An AnimationTransition.
- Returns: A CATransition key String.
*/
public func AnimationTransitionToValue(transition type: AnimationTransition) -> String {
switch type {
case .fade:
return kCATransitionFade
case .moveIn:
return kCATransitionMoveIn
case .push:
return kCATransitionPush
case .reveal:
return kCATransitionReveal
}
}
/**
Converts an AnimationTransitionDirection to a corresponding CATransition direction key.
- Parameter direction: An AnimationTransitionDirection.
- Returns: An optional CATransition direction key String.
*/
public func AnimationTransitionDirectionToValue(direction: AnimationTransitionDirection) -> String? {
switch direction {
case .default:
return nil
case .right:
return kCATransitionFromRight
case .left:
return kCATransitionFromLeft
case .top:
return kCATransitionFromBottom
case .bottom:
return kCATransitionFromTop
}
}
extension Motion {
/**
Creates a CATransition animation.
- Parameter type: An AnimationTransition.
- Parameter direction: An optional AnimationTransitionDirection.
- Parameter duration: An optional duration time.
- Returns: A CATransition.
*/
public static func transition(type: AnimationTransition, direction: AnimationTransitionDirection = .default, duration: CFTimeInterval? = nil) -> CATransition {
let animation = CATransition()
animation.type = AnimationTransitionToValue(transition: type)
animation.subtype = AnimationTransitionDirectionToValue(direction: direction)
if let v = duration {
animation.duration = v
}
return animation
}
}
...@@ -75,7 +75,7 @@ open class PulseView: View, Pulseable { ...@@ -75,7 +75,7 @@ open class PulseView: View, Pulseable {
let p = point ?? center let p = point ?? center
pulse.expandAnimation(point: p) pulse.expandAnimation(point: p)
Motion.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
self?.pulse.contractAnimation() self?.pulse.contractAnimation()
} }
} }
......
...@@ -122,8 +122,8 @@ open class SnackbarController: RootController { ...@@ -122,8 +122,8 @@ open class SnackbarController: RootController {
- Parameter status: A SnackbarStatus enum value. - Parameter status: A SnackbarStatus enum value.
*/ */
@discardableResult @discardableResult
open func animate(snackbar status: SnackbarStatus, delay: TimeInterval = 0, animations: ((Snackbar) -> Void)? = nil, completion: ((Snackbar) -> Void)? = nil) -> MotionDelayCancelBlock? { open func animate(snackbar status: SnackbarStatus, delay: TimeInterval = 0, animations: ((Snackbar) -> Void)? = nil, completion: ((Snackbar) -> Void)? = nil) -> AnimationDelayCancelBlock? {
return Motion.delay(time: delay) { [weak self, status = status, animations = animations, completion = completion] in return Animation.delay(time: delay) { [weak self, status = status, animations = animations, completion = completion] in
guard let s = self else { guard let s = self else {
return return
} }
......
...@@ -117,7 +117,7 @@ open class TableViewCell: UITableViewCell, Pulseable { ...@@ -117,7 +117,7 @@ open class TableViewCell: UITableViewCell, Pulseable {
let p = point ?? center let p = point ?? center
pulse.expandAnimation(point: p) pulse.expandAnimation(point: p)
Motion.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
self?.pulse.contractAnimation() self?.pulse.contractAnimation()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment