Commit 80ea4f02 by Daniel Dahan

development: motion issue-2: added completion block for motion animations

parent 91591377
......@@ -30,7 +30,7 @@
import UIKit
open class Button: UIButton, Pulseable {
open class Button: UIButton, Pulseable, PulseableLayer {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
......@@ -43,7 +43,7 @@ open class Button: UIButton, Pulseable {
internal var pulse: Pulse!
/// A reference to the pulse layer.
public var pulseLayer: CALayer? {
internal var pulseLayer: CALayer? {
return pulse.pulseLayer
}
......
......@@ -31,7 +31,7 @@
import UIKit
@objc(CollectionReusableView)
open class CollectionReusableView: UICollectionReusableView, Pulseable {
open class CollectionReusableView: UICollectionReusableView, Pulseable, PulseableLayer {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
......@@ -44,7 +44,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
internal var pulse: Pulse!
/// A reference to the pulse layer.
public var pulseLayer: CALayer? {
internal var pulseLayer: CALayer? {
return pulse.pulseLayer
}
......
......@@ -31,7 +31,7 @@
import UIKit
@objc(CollectionViewCell)
open class CollectionViewCell: UICollectionViewCell, Pulseable {
open class CollectionViewCell: UICollectionViewCell, Pulseable, PulseableLayer {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
......@@ -44,7 +44,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable {
internal var pulse: Pulse!
/// A reference to the pulse layer.
public var pulseLayer: CALayer? {
internal var pulseLayer: CALayer? {
return pulse.pulseLayer
}
......
......@@ -244,7 +244,7 @@ extension UIView {
isHidden = false
// Material specific.
(self as? Pulseable)?.pulseLayer?.isHidden = true
(self as? PulseableLayer)?.pulseLayer?.isHidden = true
let oldCornerRadius = layer.cornerRadius
layer.cornerRadius = 0
......@@ -292,7 +292,7 @@ extension UIView {
v.backgroundColor = backgroundColor
// Material specific.
(self as? Pulseable)?.pulseLayer?.isHidden = false
(self as? PulseableLayer)?.pulseLayer?.isHidden = false
isHidden = shouldHide
......
......@@ -179,9 +179,10 @@ extension CALayer {
/**
A function that accepts an Array of MotionAnimation values and executes them.
- Parameter animations: An Array of MotionAnimation values.
- Parameter completion: An optional completion block.
*/
open func motion(_ animations: [MotionAnimation]) {
motion(delay: 0, duration: 0.35, timingFunction: .easeInEaseOut, animations: animations)
open func motion(_ animations: [MotionAnimation], completion: (() -> Void)? = nil) {
motion(delay: 0, duration: 0.35, timingFunction: .easeInEaseOut, animations: animations, completion: completion)
}
/**
......@@ -190,8 +191,9 @@ extension CALayer {
- Parameter duration: The animation duration TimeInterval.
- Parameter timingFunction: The animation MotionAnimationTimingFunction.
- Parameter animations: An Array of MotionAnimations.
- Parameter completion: An optional completion block.
*/
fileprivate func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation]) {
fileprivate func motion(delay: TimeInterval, duration: TimeInterval, timingFunction: MotionAnimationTimingFunction, animations: [MotionAnimation], completion: (() -> Void)? = nil) {
var t = delay
for v in animations {
......@@ -319,6 +321,12 @@ extension CALayer {
g.timingFunction = MotionAnimationTimingFunctionToValue(timingFunction: tf)
s.animate(g)
guard let execute = completion else {
return
}
Motion.delay(d, execute: execute)
}
}
}
......@@ -390,9 +398,10 @@ extension UIView {
A function that accepts an Array of MotionAnimation values and executes
them on the view's backing layer.
- Parameter animations: An Array of MotionAnimation values.
- Parameter completion: An optional completion block.
*/
open func motion(_ animations: [MotionAnimation]) {
layer.motion(animations)
open func motion(_ animations: [MotionAnimation], completion: (() -> Void)? = nil) {
layer.motion(animations, completion: completion)
}
}
......
......@@ -51,9 +51,11 @@ public protocol Pulseable {
/// The opcaity value for the pulse animation.
var pulseOpacity: CGFloat { get set }
}
internal protocol PulseableLayer {
/// A reference to the pulse layer.
var pulseLayer: CALayer? { get }
var pulseLayer: CALayer? { get }
}
public struct Pulse {
......
......@@ -30,12 +30,12 @@
import UIKit
open class PulseView: View, Pulseable {
open class PulseView: View, Pulseable, PulseableLayer {
/// A Pulse reference.
internal var pulse: Pulse!
/// A reference to the pulse layer.
public var pulseLayer: CALayer? {
internal var pulseLayer: CALayer? {
return pulse.pulseLayer
}
......
......@@ -30,7 +30,7 @@
import UIKit
open class TableViewCell: UITableViewCell, Pulseable {
open class TableViewCell: UITableViewCell, Pulseable, PulseableLayer {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
......@@ -43,7 +43,7 @@ open class TableViewCell: UITableViewCell, Pulseable {
internal var pulse: Pulse!
/// A reference to the pulse layer.
public var pulseLayer: CALayer? {
internal var pulseLayer: CALayer? {
return pulse.pulseLayer
}
......
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