Commit 7a6f9cbd by Daniel Dahan

updated MotionAnimation and MotionTransition APIs

parent 06f6c0cd
...@@ -155,7 +155,7 @@ fileprivate extension CALayer { ...@@ -155,7 +155,7 @@ fileprivate extension CALayer {
return return
} }
var a = [CABasicAnimation]() var anims = [CABasicAnimation]()
let tf: CAMediaTimingFunction = targetState.timingFunction ?? CAMediaTimingFunction.from(mediaTimingFunctionType: timingFunction) let tf: CAMediaTimingFunction = targetState.timingFunction ?? CAMediaTimingFunction.from(mediaTimingFunctionType: timingFunction)
let d: TimeInterval = targetState.duration ?? duration let d: TimeInterval = targetState.duration ?? duration
// //
...@@ -183,92 +183,68 @@ fileprivate extension CALayer { ...@@ -183,92 +183,68 @@ fileprivate extension CALayer {
// } // }
// //
if let v = targetState.backgroundColor { if let v = targetState.backgroundColor {
let anim = MotionBasicAnimation.background(color: UIColor(cgColor: v)) let a = MotionBasicAnimation.background(color: UIColor(cgColor: v))
anim.fromValue = s.backgroundColor a.fromValue = s.backgroundColor
a.append(anim) anims.append(a)
} }
if let v = targetState.borderColor { if let v = targetState.borderColor {
let anim = MotionBasicAnimation.border(color: UIColor(cgColor: v)) let a = MotionBasicAnimation.border(color: UIColor(cgColor: v))
anim.fromValue = s.borderColor a.fromValue = s.borderColor
a.append(anim) anims.append(a)
} }
if let v = targetState.borderWidth { if let v = targetState.borderWidth {
let anim = MotionBasicAnimation.border(width: v) let a = MotionBasicAnimation.border(width: v)
anim.fromValue = NSNumber(floatLiteral: Double(s.borderWidth)) a.fromValue = NSNumber(floatLiteral: Double(s.borderWidth))
a.append(anim) anims.append(a)
} }
if let v = targetState.cornerRadius { if let v = targetState.cornerRadius {
let anim = MotionBasicAnimation.corner(radius: v) let a = MotionBasicAnimation.corner(radius: v)
anim.fromValue = NSNumber(floatLiteral: Double(s.cornerRadius)) a.fromValue = NSNumber(floatLiteral: Double(s.cornerRadius))
a.append(anim) anims.append(a)
} }
if let v = targetState.transform { if let v = targetState.transform {
let anim = MotionBasicAnimation.transform(transform: v) let a = MotionBasicAnimation.transform(v)
anim.fromValue = NSValue(caTransform3D: s.transform) a.fromValue = NSValue(caTransform3D: s.transform)
a.append(anim) anims.append(a)
} }
if let v = targetState.spin { if let v = targetState.spin {
var anim = MotionBasicAnimation.spinX(rotates: v.0) var a = MotionBasicAnimation.spinX(v.0)
anim.fromValue = 0 a.fromValue = NSNumber(floatLiteral: 0)
a.append(anim) anims.append(a)
anim = MotionBasicAnimation.spinY(rotates: v.1) a = MotionBasicAnimation.spinY(v.1)
anim.fromValue = 0 a.fromValue = NSNumber(floatLiteral: 0)
a.append(anim) anims.append(a)
anim = MotionBasicAnimation.spinZ(rotates: v.2) a = MotionBasicAnimation.spinZ(v.2)
anim.fromValue = 0 a.fromValue = NSNumber(floatLiteral: 0)
a.append(anim) anims.append(a)
}
if let v = targetState.position {
let a = MotionBasicAnimation.position(v)
a.fromValue = NSValue(cgPoint: s.position)
anims.append(a)
}
if let v = targetState.opacity {
let a = MotionBasicAnimation.fade(v)
a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1)
anims.append(a)
}
if let v = targetState.zPosition {
let a = MotionBasicAnimation.zPosition(v)
a.fromValue = s.value(forKeyPath: MotionAnimationKeyPath.zPosition.rawValue) ?? NSNumber(floatLiteral: 0)
anims.append(a)
} }
//
// case let .scale(to):
// a.append(MotionBasicAnimation.scale(to: to))
//
// case let .scaleX(to):
// a.append(MotionBasicAnimation.scaleX(to: to))
//
// case let .scaleY(to):
// a.append(MotionBasicAnimation.scaleY(to: to))
//
// case let .scaleZ(to):
// a.append(MotionBasicAnimation.scaleZ(to: to))
//
// case let .translate(x, y):
// a.append(MotionBasicAnimation.translate(to: CGPoint(x: x, y: y)))
//
// case let .translateX(to):
// a.append(MotionBasicAnimation.translateX(to: to))
//
// case let .translateY(to):
// a.append(MotionBasicAnimation.translateY(to: to))
//
// case let .translateZ(to):
// a.append(MotionBasicAnimation.translateZ(to: to))
//
// case .x(_), .y(_), .point(_, _):
// let position = MotionBasicAnimation.position(to: CGPoint(x: px, y: py))
// a.append(position)
//
// case let .position(x, y):
// a.append(MotionBasicAnimation.position(to: CGPoint(x: x, y: y)))
//
// case let .fade(opacity):
// let fade = MotionBasicAnimation.fade(to: opacity)
// fade.fromValue = s.value(forKey: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1)
// a.append(fade)
//
// case let .zPosition(position):
// let zPosition = MotionBasicAnimation.zPosition(position)
// zPosition.fromValue = s.value(forKey: MotionAnimationKeyPath.zPosition.rawValue) ?? NSNumber(value: 0)
// a.append(zPosition)
//
// case .width(_), .height(_), .size(_, _): // case .width(_), .height(_), .size(_, _):
// a.append(MotionBasicAnimation.size(CGSize(width: w, height: h))) // a.append(MotionBasicAnimation.size(CGSize(width: w, height: h)))
// //
...@@ -318,7 +294,7 @@ fileprivate extension CALayer { ...@@ -318,7 +294,7 @@ fileprivate extension CALayer {
// } // }
// } // }
// //
let g = Motion.animate(group: a, duration: d) let g = Motion.animate(group: anims, duration: d)
g.fillMode = MotionAnimationFillModeToValue(mode: .forwards) g.fillMode = MotionAnimationFillModeToValue(mode: .forwards)
g.isRemovedOnCompletion = false g.isRemovedOnCompletion = false
g.timingFunction = tf g.timingFunction = tf
......
...@@ -200,11 +200,11 @@ extension MotionAnimation { ...@@ -200,11 +200,11 @@ extension MotionAnimation {
/** /**
Animates the view's current x & y scale to the given scale value. Animates the view's current x & y scale to the given scale value.
- Parameter to scale: A CGFloat. - Parameter _ xy: A CGFloat.
- Returns: A MotionAnimation. - Returns: A MotionAnimation.
*/ */
public static func scale(to scale: CGFloat) -> MotionAnimation { public static func scale(_ xy: CGFloat) -> MotionAnimation {
return .scale(x: scale, y: scale) return .scale(x: xy, y: xy)
} }
/** /**
...@@ -224,36 +224,37 @@ extension MotionAnimation { ...@@ -224,36 +224,37 @@ extension MotionAnimation {
/** /**
Animates the view's current translation to the given Animates the view's current translation to the given
point value (x & y), and a z value. point value (x & y), and a z value.
- Parameter to point: A CGPoint. - Parameter _ point: A CGPoint.
- Parameter z: A CGFloat, default is 0. - Parameter z: A CGFloat, default is 0.
- Returns: A MotionAnimation. - Returns: A MotionAnimation.
*/ */
public static func translate(to point: CGPoint, z: CGFloat = 0) -> MotionAnimation { public static func translate(_ point: CGPoint, z: CGFloat = 0) -> MotionAnimation {
return .translate(x: point.x, y: point.y, z: z) return .translate(x: point.x, y: point.y, z: z)
} }
/** /**
Animates the view's current position to the given point. Animates the view's current position to the given point.
- Parameter to point: A CGPoint. - Parameter _ point: A CGPoint.
- Returns: A MotionAnimation. - Returns: A MotionAnimation.
*/ */
public static func position(to point: CGPoint) -> MotionAnimation { public static func position(_ point: CGPoint) -> MotionAnimation {
return MotionAnimation { return MotionAnimation {
$0.position = point $0.position = point
} }
} }
/// Fades the view out during a transition. /// Fades the view in during an animation.
public static var fade = MotionAnimation { public static var fadeIn = MotionAnimation.fade(1)
$0.opacity = 0
} /// Fades the view out during an animation.
public static var fadeOut = MotionAnimation.fade(0)
/** /**
Animates the view's current opacity to the given one. Animates the view's current opacity to the given one.
- Parameter to opacity: A Float value. - Parameter _ opacity: A Double value.
- Returns: A MotionAnimation. - Returns: A MotionAnimation.
*/ */
public static func fade(to opacity: Float) -> MotionAnimation { public static func fade(_ opacity: Double) -> MotionAnimation {
return MotionAnimation { return MotionAnimation {
$0.opacity = opacity $0.opacity = opacity
} }
...@@ -371,7 +372,7 @@ extension MotionAnimation { ...@@ -371,7 +372,7 @@ extension MotionAnimation {
/** /**
Sets the view's animation duration to the longest Sets the view's animation duration to the longest
running animation within a transition. running animation.
*/ */
public static var preferredDurationMatchesLongest = MotionAnimation.duration(.infinity) public static var preferredDurationMatchesLongest = MotionAnimation.duration(.infinity)
...@@ -488,9 +489,9 @@ public struct MotionBasicAnimation { ...@@ -488,9 +489,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func background(color: UIColor) -> CABasicAnimation { public static func background(color: UIColor) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .backgroundColor) let a = CABasicAnimation(keyPath: .backgroundColor)
animation.toValue = color.cgColor a.toValue = color.cgColor
return animation return a
} }
/** /**
...@@ -499,9 +500,9 @@ public struct MotionBasicAnimation { ...@@ -499,9 +500,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func barTint(color: UIColor) -> CABasicAnimation { public static func barTint(color: UIColor) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .barTintColor) let a = CABasicAnimation(keyPath: .barTintColor)
animation.toValue = color.cgColor a.toValue = color.cgColor
return animation return a
} }
/** /**
...@@ -510,9 +511,9 @@ public struct MotionBasicAnimation { ...@@ -510,9 +511,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func border(color: UIColor) -> CABasicAnimation { public static func border(color: UIColor) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .borderColor) let a = CABasicAnimation(keyPath: .borderColor)
animation.toValue = color.cgColor a.toValue = color.cgColor
return animation return a
} }
/** /**
...@@ -521,9 +522,9 @@ public struct MotionBasicAnimation { ...@@ -521,9 +522,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func border(width: CGFloat) -> CABasicAnimation { public static func border(width: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .borderWidth) let a = CABasicAnimation(keyPath: .borderWidth)
animation.toValue = width a.toValue = NSNumber(floatLiteral: Double(width))
return animation return a
} }
/** /**
...@@ -532,183 +533,72 @@ public struct MotionBasicAnimation { ...@@ -532,183 +533,72 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func corner(radius: CGFloat) -> CABasicAnimation { public static func corner(radius: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .cornerRadius) let a = CABasicAnimation(keyPath: .cornerRadius)
animation.toValue = radius a.toValue = NSNumber(floatLiteral: Double(radius))
return animation return a
} }
/** /**
Creates a CABasicAnimation for the transform key path. Creates a CABasicAnimation for the transform key path.
- Parameter transform: A CATransform3D object. - Parameter _ t: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
public static func transform(transform: CATransform3D) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .transform)
animation.toValue = NSValue(caTransform3D: transform)
return animation
}
/**
Creates a CABasicAnimation for the transform.rotate key path.
- Parameter rotates: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spin(rotates: CGFloat) -> CABasicAnimation { public static func transform(_ t: CATransform3D) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotate) let a = CABasicAnimation(keyPath: .transform)
animation.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotates)) a.toValue = NSValue(caTransform3D: t)
return animation return a
} }
/** /**
Creates a CABasicAnimation for the transform.rotate.x key path. Creates a CABasicAnimation for the transform.rotate.x key path.
- Parameter rotates: An optional CGFloat. - Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinX(rotates: CGFloat) -> CABasicAnimation { public static func spinX(_ rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotateX) let a = CABasicAnimation(keyPath: .rotateX)
animation.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotates)) a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return animation return a
} }
/** /**
Creates a CABasicAnimation for the transform.rotate.y key path. Creates a CABasicAnimation for the transform.rotate.y key path.
- Parameter rotates: An optional CGFloat. - Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinY(rotates: CGFloat) -> CABasicAnimation { public static func spinY(_ rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotateY) let a = CABasicAnimation(keyPath: .rotateY)
animation.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotates)) a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return animation return a
} }
/** /**
Creates a CABasicAnimation for the transform.rotate.z key path. Creates a CABasicAnimation for the transform.rotate.z key path.
- Parameter rotates: An optional CGFloat. - Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func spinZ(rotates: CGFloat) -> CABasicAnimation { public static func spinZ(_ rotations: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .rotateZ) let a = CABasicAnimation(keyPath: .rotateZ)
animation.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotates)) a.toValue = NSNumber(value: Double(CGFloat(Double.pi) * 2 * rotations))
return animation return a
}
/**
Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func scale(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scale)
animation.toValue = NSNumber(value: Double(scale))
return animation
}
/**
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func scaleX(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleX)
animation.toValue = NSNumber(value: Double(scale))
return animation
}
/**
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func scaleY(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleY)
animation.toValue = NSNumber(value: Double(scale))
return animation
}
/**
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func scaleZ(to scale: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .scaleZ)
animation.toValue = NSNumber(value: Double(scale))
return animation
}
/**
Creates a CABasicAnimation for the transform.translation key path.
- Parameter point: A CGPoint.
- Returns: A CABasicAnimation.
*/
public static func translate(to point: CGPoint) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translation)
animation.toValue = NSValue(cgPoint: point)
return animation
}
/**
Creates a CABasicAnimation for the transform.translation.x key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func translateX(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationX)
animation.toValue = NSNumber(value: Double(translation))
return animation
}
/**
Creates a CABasicAnimation for the transform.translation.y key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func translateY(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationY)
animation.toValue = NSNumber(value: Double(translation))
return animation
}
/**
Creates a CABasicAnimation for the transform.translation.z key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func translateZ(to translation: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .translationZ)
animation.toValue = NSNumber(value: Double(translation))
return animation
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter x: A CGFloat.
- Parameter y: A CGFloat.
- Returns: A CABasicAnimation.
*/
public static func position(x: CGFloat, y: CGFloat) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .position)
animation.toValue = NSValue(cgPoint: CGPoint(x: x, y: y))
return animation
} }
/** /**
Creates a CABasicAnimation for the position key path. Creates a CABasicAnimation for the position key path.
- Parameter to point: A CGPoint. - Parameter _ point: A CGPoint.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func position(to point: CGPoint) -> CABasicAnimation { public static func position(_ point: CGPoint) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .position) let a = CABasicAnimation(keyPath: .position)
animation.toValue = NSValue(cgPoint: point) a.toValue = NSValue(cgPoint: point)
return animation return a
} }
/** /**
Creates a CABasicAnimation for the opacity key path. Creates a CABasicAnimation for the opacity key path.
- Parameter to opacity: A Double. - Parameter _ opacity: A Double.
- Returns: A CABasicAnimation. - Returns: A CABasicAnimation.
*/ */
public static func fade(to opacity: Double) -> CABasicAnimation { public static func fade(_ opacity: Double) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: .opacity) let animation = CABasicAnimation(keyPath: .opacity)
animation.toValue = NSNumber(floatLiteral: opacity) animation.toValue = NSNumber(floatLiteral: opacity)
return animation return animation
......
...@@ -42,7 +42,7 @@ public struct MotionAnimationState { ...@@ -42,7 +42,7 @@ public struct MotionAnimationState {
public var spin: (CGFloat, CGFloat, CGFloat)? public var spin: (CGFloat, CGFloat, CGFloat)?
/// A reference to the opacity. /// A reference to the opacity.
public var opacity: Float? public var opacity: Double?
/// A reference to the cornerRadius. /// A reference to the cornerRadius.
public var cornerRadius: CGFloat? public var cornerRadius: CGFloat?
...@@ -113,18 +113,18 @@ public struct MotionAnimationState { ...@@ -113,18 +113,18 @@ public struct MotionAnimationState {
extension MotionAnimationState { extension MotionAnimationState {
/** /**
Adds a MotionAnimation to the current state. Adds a MotionAnimation to the current state.
- Parameter _ animation: A MotionAnimation. - Parameter _ element: A MotionAnimation.
*/ */
public mutating func append(_ animation: MotionAnimation) { public mutating func append(_ element: MotionAnimation) {
animation.apply(&self) element.apply(&self)
} }
/** /**
Adds an Array of MotionAnimations to the current state. Adds an Array of MotionAnimations to the current state.
- Parameter contentsOf animations: An Array of MotionAnimations. - Parameter contentsOf elements: An Array of MotionAnimations.
*/ */
public mutating func append(contentsOf animations: [MotionAnimation]) { public mutating func append(contentsOf elements: [MotionAnimation]) {
for v in animations { for v in elements {
v.apply(&self) v.apply(&self)
} }
} }
......
...@@ -191,11 +191,11 @@ extension MotionTransition { ...@@ -191,11 +191,11 @@ extension MotionTransition {
/** /**
Animates the view's current x & y scale to the given scale value. Animates the view's current x & y scale to the given scale value.
- Parameter to scale: A CGFloat. - Parameter _ xy: A CGFloat.
- Returns: A MotionTransition. - Returns: A MotionTransition.
*/ */
public static func scale(to scale: CGFloat) -> MotionTransition { public static func scale(_ xy: CGFloat) -> MotionTransition {
return .scale(x: scale, y: scale) return .scale(x: xy, y: xy)
} }
/** /**
...@@ -215,20 +215,20 @@ extension MotionTransition { ...@@ -215,20 +215,20 @@ extension MotionTransition {
/** /**
Animates the view's current translation to the given Animates the view's current translation to the given
point value (x & y), and a z value. point value (x & y), and a z value.
- Parameter to point: A CGPoint. - Parameter _ point: A CGPoint.
- Parameter z: A CGFloat, default is 0. - Parameter z: A CGFloat, default is 0.
- Returns: A MotionTransition. - Returns: A MotionTransition.
*/ */
public static func translate(to point: CGPoint, z: CGFloat = 0) -> MotionTransition { public static func translate(_ point: CGPoint, z: CGFloat = 0) -> MotionTransition {
return .translate(x: point.x, y: point.y, z: z) return .translate(x: point.x, y: point.y, z: z)
} }
/** /**
Animates the view's current position to the given point. Animates the view's current position to the given point.
- Parameter to point: A CGPoint. - Parameter _ point: A CGPoint.
- Returns: A MotionTransition. - Returns: A MotionTransition.
*/ */
public static func position(to point: CGPoint) -> MotionTransition { public static func position(_ point: CGPoint) -> MotionTransition {
return MotionTransition { return MotionTransition {
$0.position = point $0.position = point
} }
...@@ -239,17 +239,18 @@ extension MotionTransition { ...@@ -239,17 +239,18 @@ extension MotionTransition {
$0.nonFade = true $0.nonFade = true
} }
/// Fades the view in during a transition.
public static var fadeIn = MotionTransition.fade(1)
/// Fades the view out during a transition. /// Fades the view out during a transition.
public static var fade = MotionTransition { public static var fadeOut = MotionTransition.fade(0)
$0.opacity = 0
}
/** /**
Animates the view's current opacity to the given one. Animates the view's current opacity to the given one.
- Parameter to opacity: A Float value. - Parameter to opacity: A Double value.
- Returns: A MotionTransition. - Returns: A MotionTransition.
*/ */
public static func fade(to opacity: Float) -> MotionTransition { public static func fade(_ opacity: Double) -> MotionTransition {
return MotionTransition { return MotionTransition {
$0.opacity = opacity $0.opacity = opacity
} }
......
...@@ -58,7 +58,7 @@ public struct MotionTransitionState { ...@@ -58,7 +58,7 @@ public struct MotionTransitionState {
public var transform: CATransform3D? public var transform: CATransform3D?
/// A reference to the opacity. /// A reference to the opacity.
public var opacity: Float? public var opacity: Double?
/// A reference to the cornerRadius. /// A reference to the cornerRadius.
public var cornerRadius: CGFloat? public var cornerRadius: CGFloat?
...@@ -162,18 +162,18 @@ public struct MotionTransitionState { ...@@ -162,18 +162,18 @@ public struct MotionTransitionState {
extension MotionTransitionState { extension MotionTransitionState {
/** /**
Adds a MotionTransition to the current state. Adds a MotionTransition to the current state.
- Parameter _ transition: A MotionTransition. - Parameter _ element: A MotionTransition.
*/ */
public mutating func append(_ transition: MotionTransition) { public mutating func append(_ element: MotionTransition) {
transition.apply(&self) element.apply(&self)
} }
/** /**
Adds an Array of MotionTransitions to the current state. Adds an Array of MotionTransitions to the current state.
- Parameter contentsOf transitions: An Array of MotionTransitions. - Parameter contentsOf elements: An Array of MotionTransitions.
*/ */
public mutating func append(contentsOf transitions: [MotionTransition]) { public mutating func append(contentsOf elements: [MotionTransition]) {
for v in transitions { for v in elements {
v.apply(&self) v.apply(&self)
} }
} }
......
...@@ -261,37 +261,37 @@ class TransitionPreprocessor: MotionPreprocessor { ...@@ -261,37 +261,37 @@ class TransitionPreprocessor: MotionPreprocessor {
switch defaultAnimation { switch defaultAnimation {
case .push(let direction): case .push(let direction):
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true)), context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState), .beginWith(transitions: shadowState),
.timingFunction(.deceleration)]) .timingFunction(.deceleration)])
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false) / 3), context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false) / 3),
.overlay(color: .black, opacity: 0.1), .overlay(color: .black, opacity: 0.1),
.timingFunction(.deceleration)]) .timingFunction(.deceleration)])
case .pull(let direction): case .pull(let direction):
m.insertToViewFirst = true m.insertToViewFirst = true
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false)), context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState)]) .beginWith(transitions: shadowState)])
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true) / 3), context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true) / 3),
.overlay(color: .black, opacity: 0.1)]) .overlay(color: .black, opacity: 0.1)])
case .slide(let direction): case .slide(let direction):
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false))]) context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false))])
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true))]) context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true))])
case .zoomSlide(let direction): case .zoomSlide(let direction):
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false)), .scale(to: 0.8)]) context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false)), .scale(0.8)])
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true)), .scale(to: 0.8)]) context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true)), .scale(0.8)])
case .cover(let direction): case .cover(let direction):
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true)), context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState), .beginWith(transitions: shadowState),
.timingFunction(.deceleration)]) .timingFunction(.deceleration)])
...@@ -302,43 +302,43 @@ class TransitionPreprocessor: MotionPreprocessor { ...@@ -302,43 +302,43 @@ class TransitionPreprocessor: MotionPreprocessor {
case .uncover(let direction): case .uncover(let direction):
m.insertToViewFirst = true m.insertToViewFirst = true
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false)), context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState)]) .beginWith(transitions: shadowState)])
context[tv]!.append(contentsOf: [.overlay(color: .black, opacity: 0.1)]) context[tv]!.append(contentsOf: [.overlay(color: .black, opacity: 0.1)])
case .pageIn(let direction): case .pageIn(let direction):
context[tv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: true)), context[tv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: true)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState), .beginWith(transitions: shadowState),
.timingFunction(.deceleration)]) .timingFunction(.deceleration)])
context[fv]!.append(contentsOf: [.scale(to: 0.7), context[fv]!.append(contentsOf: [.scale(0.7),
.overlay(color: .black, opacity: 0.1), .overlay(color: .black, opacity: 0.1),
.timingFunction(.deceleration)]) .timingFunction(.deceleration)])
case .pageOut(let direction): case .pageOut(let direction):
m.insertToViewFirst = true m.insertToViewFirst = true
context[fv]!.append(contentsOf: [.translate(to: shift(direction: direction, isAppearing: false)), context[fv]!.append(contentsOf: [.translate(shift(direction: direction, isAppearing: false)),
.shadow(opacity: 0), .shadow(opacity: 0),
.beginWith(transitions: shadowState)]) .beginWith(transitions: shadowState)])
context[tv]!.append(contentsOf: [.scale(to: 0.7), context[tv]!.append(contentsOf: [.scale(0.7),
.overlay(color: .black, opacity: 0.1)]) .overlay(color: .black, opacity: 0.1)])
case .fade: case .fade:
// TODO: clean up this. overFullScreen logic shouldn't be here // TODO: clean up this. overFullScreen logic shouldn't be here
if !(fromOverFullScreen && !isPresenting) { if !(fromOverFullScreen && !isPresenting) {
context[tv] = [.fade] context[tv] = [.fadeOut]
} }
#if os(tvOS) #if os(tvOS)
context[fromView] = [.fade] context[fromView] = [.fade]
#else #else
if (!isPresenting && toOverFullScreen) || !fv.isOpaque || (fv.backgroundColor?.alphaComponent ?? 1) < 1 { if (!isPresenting && toOverFullScreen) || !fv.isOpaque || (fv.backgroundColor?.alphaComponent ?? 1) < 1 {
context[fv] = [.fade] context[fv] = [.fadeOut]
} }
#endif #endif
...@@ -347,12 +347,12 @@ class TransitionPreprocessor: MotionPreprocessor { ...@@ -347,12 +347,12 @@ class TransitionPreprocessor: MotionPreprocessor {
case .zoom: case .zoom:
m.insertToViewFirst = true m.insertToViewFirst = true
context[fv]!.append(contentsOf: [.scale(to: 1.3), .fade]) context[fv]!.append(contentsOf: [.scale(1.3), .fadeOut])
context[tv]!.append(contentsOf: [.scale(to: 0.7)]) context[tv]!.append(contentsOf: [.scale(0.7)])
case .zoomOut: case .zoomOut:
context[tv]!.append(contentsOf: [.scale(to: 1.3), .fade]) context[tv]!.append(contentsOf: [.scale(1.3), .fadeOut])
context[fv]!.append(contentsOf: [.scale(to: 0.7)]) context[fv]!.append(contentsOf: [.scale(0.7)])
default: default:
fatalError("Not implemented") fatalError("Not implemented")
......
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