Commit 80ea4f02 by Daniel Dahan

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

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