Commit e0edc2b7 by Daniel Dahan

updated Motion internals to remove motion only animations and handle TabBar…

updated Motion internals to remove motion only animations and handle TabBar animations when being pushed with hideBottomBarWhenPushed
parent 0c04b36f
......@@ -40,7 +40,11 @@ internal class MotionCoreAnimationViewContext: MotionAnimatorViewContext {
/// Layer which holds the content.
fileprivate var contentLayer: CALayer? {
return snapshot.layer.sublayers?.get(0)
let firstLayer = snapshot.layer.sublayers?.get(0)
if firstLayer?.bounds == snapshot.bounds {
return firstLayer
}
return nil
}
/// Layer which holds the overlay.
......@@ -316,7 +320,8 @@ fileprivate extension MotionCoreAnimationViewContext {
anim.damping = damping
self.addAnimation(anim, for: key, to: layer)
} else {
self.animations.append((layer, key, anim))
layer.removeAnimation(forKey: key)
addAnimation(anim, for: key, to: layer)
}
}
......@@ -324,11 +329,16 @@ fileprivate extension MotionCoreAnimationViewContext {
CATransaction.begin()
CATransaction.setAnimationTimingFunction(timingFunction)
UIView.animate(withDuration: duration, delay: delay, options: [], animations: animations, completion: nil)
CATransaction.commit()
let addedAnimations = CALayer.motionAddedAnimations!
CALayer.motionAddedAnimations = nil
self.animations.append(contentsOf: addedAnimations)
for (layer, key, anim) in addedAnimations {
layer.removeAnimation(forKey: key)
self.addAnimation(anim, for: key, to: layer)
}
CATransaction.commit()
}
}
......@@ -339,8 +349,9 @@ fileprivate extension MotionCoreAnimationViewContext {
- Parameter to layer: A CALayer.
*/
func addAnimation(_ animation: CAAnimation, for key: String, to layer: CALayer) {
animations.append((layer, key, animation))
layer.add(animation, forKey: key)
let motionAnimationKey = "motion.\(key)"
animations.append((layer, motionAnimationKey, animation))
layer.add(animation, forKey: motionAnimationKey)
}
/**
......
......@@ -44,10 +44,13 @@ internal extension CALayer {
@objc
dynamic func motionAdd(anim: CAAnimation, forKey: String?) {
let copiedAnim = anim.copy() as! CAAnimation
copiedAnim.delegate = nil // having delegate resulted some weird animation behavior
CALayer.motionAddedAnimations?.append((self, forKey!, copiedAnim))
motionAdd(anim: anim, forKey: forKey)
if nil == CALayer.motionAddedAnimations {
motionAdd(anim: anim, forKey: forKey)
} else {
let copiedAnim = anim.copy() as! CAAnimation
copiedAnim.delegate = nil // having delegate resulted some weird animation behavior
CALayer.motionAddedAnimations?.append((self, forKey!, copiedAnim))
}
}
/// Retrieves all currently running animations for the layer.
......@@ -77,6 +80,17 @@ internal extension CALayer {
return t
}
/// Removes all Motion animations.
func removeAllMotionAnimations() {
guard let keys = animationKeys() else {
return
}
for animationKey in keys where animationKey.hasPrefix("motion.") {
removeAnimation(forKey: animationKey)
}
}
}
public extension CALayer {
......
......@@ -76,7 +76,7 @@ public extension CGSize {
public extension CGRect {
/// A center point based on the origin and size values.
var center: CGPoint {
return CGPoint(x: origin.x + size.width / 2, y: origin.y + size.height / 2)
return CGPoint(x: origin.x + width / 2, y: origin.y + height / 2)
}
/// The bounding box size based from from the frame's rect.
......@@ -151,7 +151,7 @@ public extension CGPoint {
- Parameter right: A CGPoint.
- Returns: A CGPoint.
*/
public func +(left: CGPoint, right: CGPoint) -> CGPoint {
public func + (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x + right.x, y: left.y + right.y)
}
......@@ -161,7 +161,7 @@ public func +(left: CGPoint, right: CGPoint) -> CGPoint {
- Parameter right: A CGPoint.
- Returns: A CGPoint.
*/
public func -(left: CGPoint, right: CGPoint) -> CGPoint {
public func - (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x - right.x, y: left.y - right.y)
}
......@@ -171,7 +171,7 @@ public func -(left: CGPoint, right: CGPoint) -> CGPoint {
- Parameter right: A CGFloat.
- Returns: A CGPoint.
*/
public func /(left: CGPoint, right: CGFloat) -> CGPoint {
public func / (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x / right, y: left.y / right)
}
......@@ -181,7 +181,7 @@ public func /(left: CGPoint, right: CGFloat) -> CGPoint {
- Parameter right: A CGPoint.
- Returns: A CGPoint.
*/
public func /(left: CGPoint, right: CGPoint) -> CGPoint {
public func / (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x / right.x, y: left.y / right.y)
}
......@@ -191,7 +191,7 @@ public func /(left: CGPoint, right: CGPoint) -> CGPoint {
- Parameter right: A CGSize.
- Returns: A CGPoint.
*/
public func /(left: CGPoint, right: CGSize) -> CGPoint {
public func / (left: CGPoint, right: CGSize) -> CGPoint {
return CGPoint(x: left.x / right.width, y: left.y / right.height)
}
......@@ -201,7 +201,7 @@ public func /(left: CGPoint, right: CGSize) -> CGPoint {
- Parameter right: A CGSize.
- Returns: A CGSize.
*/
public func /(left: CGSize, right: CGSize) -> CGSize {
public func / (left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width / right.width, height: left.height / right.height)
}
......@@ -211,7 +211,7 @@ public func /(left: CGSize, right: CGSize) -> CGSize {
- Parameter right: A CGFloat.
- Returns: A CGPoint.
*/
public func *(left: CGPoint, right: CGFloat) -> CGPoint {
public func * (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x * right, y: left.y * right)
}
......@@ -221,7 +221,7 @@ public func *(left: CGPoint, right: CGFloat) -> CGPoint {
- Parameter right: A CGSize.
- Returns: A CGPoint.
*/
public func *(left: CGPoint, right: CGSize) -> CGPoint {
public func * (left: CGPoint, right: CGSize) -> CGPoint {
return CGPoint(x: left.x * right.width, y: left.y * right.width)
}
......@@ -231,7 +231,7 @@ public func *(left: CGPoint, right: CGSize) -> CGPoint {
- Parameter right: A CGPoint.
- Returns: A CGPoint.
*/
public func *(left: CGFloat, right: CGPoint) -> CGPoint {
public func * (left: CGFloat, right: CGPoint) -> CGPoint {
return right * left
}
......@@ -241,7 +241,7 @@ public func *(left: CGFloat, right: CGPoint) -> CGPoint {
- Parameter right: A CGPoint.
- Returns: A CGPoint.
*/
public func *(left: CGPoint, right: CGPoint) -> CGPoint {
public func * (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x * right.x, y: left.y * right.y)
}
......@@ -251,7 +251,7 @@ public func *(left: CGPoint, right: CGPoint) -> CGPoint {
- Parameter right: A CGFloat.
- Returns: A CGSize.
*/
public func *(left: CGSize, right: CGFloat) -> CGSize {
public func * (left: CGSize, right: CGFloat) -> CGSize {
return CGSize(width: left.width * right, height: left.height * right)
}
......@@ -261,8 +261,8 @@ public func *(left: CGSize, right: CGFloat) -> CGSize {
- Parameter right: A CGSize.
- Returns: A CGSize.
*/
public func *(left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width * right.width, height: left.height * right.width)
public func * (left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width * right.width, height: left.height * right.height)
}
/**
......@@ -271,7 +271,7 @@ public func *(left: CGSize, right: CGSize) -> CGSize {
- Parameter rhs: A CATransform3D.
- Returns: A Bool.
*/
public func ==(lhs: CATransform3D, rhs: CATransform3D) -> Bool {
public func == (lhs: CATransform3D, rhs: CATransform3D) -> Bool {
var lhs = lhs
var rhs = rhs
return 0 == memcmp(&lhs, &rhs, MemoryLayout<CATransform3D>.size)
......@@ -283,7 +283,7 @@ public func ==(lhs: CATransform3D, rhs: CATransform3D) -> Bool {
- Parameter rhs: A CATransform3D.
- Returns: A Bool.
*/
public func !=(lhs: CATransform3D, rhs: CATransform3D) -> Bool {
public func != (lhs: CATransform3D, rhs: CATransform3D) -> Bool {
return !(lhs == rhs)
}
......@@ -292,8 +292,8 @@ public func !=(lhs: CATransform3D, rhs: CATransform3D) -> Bool {
- Parameter point: A CGPoint.
- Returns: A CGPoint.
*/
public prefix func -(point: CGPoint) -> CGPoint {
return CGPoint.zero - point
public prefix func - (point: CGPoint) -> CGPoint {
return .zero - point
}
/**
......
......@@ -92,7 +92,7 @@ internal extension MotionContext {
*/
func process(views: [UIView], identifierMap: inout [String: UIView]) {
for v in views {
v.layer.removeAllAnimations()
v.layer.removeAllMotionAnimations()
let targetState: MotionTargetState?
......@@ -438,7 +438,7 @@ internal extension MotionContext {
if view != snapshot {
snapshot.removeFromSuperview()
} else {
view.layer.removeAllAnimations()
view.layer.removeAllMotionAnimations()
}
}
}
......@@ -452,7 +452,7 @@ internal extension MotionContext {
if rootView != snapshot {
snapshot.removeFromSuperview()
} else {
rootView.layer.removeAllAnimations()
rootView.layer.removeAllMotionAnimations()
}
}
......
......@@ -125,6 +125,12 @@ extension MotionTransition {
completionCallback?(isFinishing)
if isFinishing {
toViewController?.tabBarController?.tabBar.layer.removeAllAnimations()
} else {
fromViewController?.tabBarController?.tabBar.layer.removeAllAnimations()
}
let tContext = transitionContext
let fvc = fromViewController
let tvc = toViewController
......
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