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