From d441a23fa18169efbd48b9a970b92d0d4655db88 Mon Sep 17 00:00:00 2001 From: Adam Modzelewski Date: Mon, 24 Oct 2016 15:52:39 +0200 Subject: [PATCH] Update syntax with swift 3.0 update method parameter names --- Sources/extensions/Tween+Double.swift | 16 +++--- Sources/extensions/Tween+UIView.swift | 56 +++++++++---------- Sources/extensions/Tweenable+Repeat.swift | 2 +- Sources/morphable/FloatMorpher.swift | 4 +- .../morphable/Morphable+CATransform3D.swift | 34 +++++------ .../Morphable+CGAffineTransform.swift | 14 ++--- Sources/morphable/Morphable+CGFloat.swift | 2 +- Sources/morphable/Morphable+CGPoint.swift | 6 +- Sources/morphable/Morphable+CGRect.swift | 6 +- Sources/morphable/Morphable+CGSize.swift | 6 +- Sources/morphable/Morphable+Double.swift | 2 +- Sources/morphable/Morphable.swift | 2 +- Sources/scheduler/Proxy.swift | 4 +- Sources/scheduler/Scheduler.swift | 20 +++---- Sources/scheduler/Subscriber.swift | 2 +- Sources/timeline/TimeLine.swift | 44 +++++++-------- Sources/tween/Tween.swift | 8 +-- Sources/tweenable/AbstractTweenable.swift | 6 +- Sources/tweenable/Tweenable.swift | 4 +- TRXTests/mocks/MockSubscriber.swift | 2 +- TRXTests/mocks/MockTweenable.swift | 4 +- .../Morphable+CATransform3DSpec.swift | 6 +- .../Morphable+CGAffineTransformSpec.swift | 6 +- .../morphable/Morphable+CGFloatSpec.swift | 6 +- .../morphable/Morphable+CGPointSpec.swift | 8 +-- .../morphable/Morphable+CGRectSpec.swift | 8 +-- .../morphable/Morphable+CGSizeSpec.swift | 6 +- .../shared/TweenableSharedExmaples.swift | 14 ++--- TRXTests/specs/timeline/TimeLineSpec.swift | 44 +++++++-------- TRXTests/specs/tween/TweenSpec.swift | 28 +++++----- 30 files changed, 186 insertions(+), 184 deletions(-) diff --git a/Sources/extensions/Tween+Double.swift b/Sources/extensions/Tween+Double.swift index f62bb11..753af40 100644 --- a/Sources/extensions/Tween+Double.swift +++ b/Sources/extensions/Tween+Double.swift @@ -1,12 +1,12 @@ public extension Double { - public func trxTo(_ to: Double, - time: TimeInterval = 0.3, - delay: TimeInterval = 0, - ease: @escaping Ease.TimingFunction = Ease.Quad.easeOut, - key: String? = nil, - onStart: StartClosure? = nil, - onComplete: CompletionClosure? = nil, - onUpdate: @escaping Tween.UpdateClosure + public func trx(to: Double, + time: TimeInterval = 0.3, + delay: TimeInterval = 0, + ease: @escaping Ease.TimingFunction = Ease.Quad.easeOut, + key: String? = nil, + onStart: StartClosure? = nil, + onComplete: CompletionClosure? = nil, + onUpdate: @escaping Tween.UpdateClosure ) -> Tween { return Tween(from: self, to: to, diff --git a/Sources/extensions/Tween+UIView.swift b/Sources/extensions/Tween+UIView.swift index 8d22b4b..d2be6e0 100644 --- a/Sources/extensions/Tween+UIView.swift +++ b/Sources/extensions/Tween+UIView.swift @@ -2,13 +2,13 @@ import UIKit extension UIView { - func trxCenterTo(_ to: CGPoint, - time: TimeInterval = 0.3, - delay: TimeInterval = 0, - ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, - onStart: StartClosure? = nil, - onComplete: CompletionClosure? = nil, - onUpdate: Tween.UpdateClosure? = nil) { + public func trxCenter(to: CGPoint, + time: TimeInterval = 0.3, + delay: TimeInterval = 0, + ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, + onStart: StartClosure? = nil, + onComplete: CompletionClosure? = nil, + onUpdate: Tween.UpdateClosure? = nil) { Tween(from: self.center, to: to, time: time, @@ -21,13 +21,13 @@ }).start() } - func trxCenterFrom(_ from: CGPoint, - time: TimeInterval = 0.3, - delay: TimeInterval = 0, - ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, - onStart: StartClosure? = nil, - onComplete: CompletionClosure? = nil, - onUpdate: Tween.UpdateClosure? = nil) { + public func trxCenter(from: CGPoint, + time: TimeInterval = 0.3, + delay: TimeInterval = 0, + ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, + onStart: StartClosure? = nil, + onComplete: CompletionClosure? = nil, + onUpdate: Tween.UpdateClosure? = nil) { Tween(from: from, to: self.center, time: time, @@ -40,13 +40,13 @@ }).start() } - func trxFrameTo(_ to: CGRect, - time: TimeInterval = 0.3, - delay: TimeInterval = 0, - ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, - onStart: StartClosure? = nil, - onComplete: CompletionClosure? = nil, - onUpdate: Tween.UpdateClosure? = nil) { + public func trxFrame(to: CGRect, + time: TimeInterval = 0.3, + delay: TimeInterval = 0, + ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, + onStart: StartClosure? = nil, + onComplete: CompletionClosure? = nil, + onUpdate: Tween.UpdateClosure? = nil) { Tween(from: self.frame, to: to, time: time, @@ -59,13 +59,13 @@ }).start() } - func trxFrameFrom(_ from: CGRect, - time: TimeInterval = 0.3, - delay: TimeInterval = 0, - ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, - onStart: StartClosure? = nil, - onComplete: CompletionClosure? = nil, - onUpdate: Tween.UpdateClosure? = nil) { + public func trxFrame(from: CGRect, + time: TimeInterval = 0.3, + delay: TimeInterval = 0, + ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut, + onStart: StartClosure? = nil, + onComplete: CompletionClosure? = nil, + onUpdate: Tween.UpdateClosure? = nil) { Tween(from: from, to: self.frame, time: time, diff --git a/Sources/extensions/Tweenable+Repeat.swift b/Sources/extensions/Tweenable+Repeat.swift index 61e5e8c..c04702a 100644 --- a/Sources/extensions/Tweenable+Repeat.swift +++ b/Sources/extensions/Tweenable+Repeat.swift @@ -8,7 +8,7 @@ public extension Tweenable { public func repeatTimes(_ times: UInt) -> TimeLine { let timeLine = TimeLine() for _ in 0.. CGFloat { + public func tween(from: CGFloat, + to: CGFloat, + ratio: Double) -> CGFloat { return from.distance(to: to) * CGFloat(ratio) / precision + from } diff --git a/Sources/morphable/Morphable+CATransform3D.swift b/Sources/morphable/Morphable+CATransform3D.swift index 3681601..de8405f 100644 --- a/Sources/morphable/Morphable+CATransform3D.swift +++ b/Sources/morphable/Morphable+CATransform3D.swift @@ -12,25 +12,25 @@ extension CATransform3D: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CATransform3D, + public static func morph(from: CATransform3D, to: CATransform3D, ratio: Double) -> CATransform3D { - return CATransform3D(m11: morpher.tween(from.m11, to: to.m11, ratio: ratio), - m12: morpher.tween(from.m12, to: to.m12, ratio: ratio), - m13: morpher.tween(from.m13, to: to.m13, ratio: ratio), - m14: morpher.tween(from.m14, to: to.m14, ratio: ratio), - m21: morpher.tween(from.m21, to: to.m21, ratio: ratio), - m22: morpher.tween(from.m22, to: to.m22, ratio: ratio), - m23: morpher.tween(from.m23, to: to.m23, ratio: ratio), - m24: morpher.tween(from.m24, to: to.m24, ratio: ratio), - m31: morpher.tween(from.m31, to: to.m31, ratio: ratio), - m32: morpher.tween(from.m32, to: to.m32, ratio: ratio), - m33: morpher.tween(from.m33, to: to.m33, ratio: ratio), - m34: morpher.tween(from.m34, to: to.m34, ratio: ratio), - m41: morpher.tween(from.m41, to: to.m41, ratio: ratio), - m42: morpher.tween(from.m42, to: to.m42, ratio: ratio), - m43: morpher.tween(from.m43, to: to.m43, ratio: ratio), - m44: morpher.tween(from.m44, to: to.m44, ratio: ratio)) + return CATransform3D(m11: morpher.tween(from: from.m11, to: to.m11, ratio: ratio), + m12: morpher.tween(from: from.m12, to: to.m12, ratio: ratio), + m13: morpher.tween(from: from.m13, to: to.m13, ratio: ratio), + m14: morpher.tween(from: from.m14, to: to.m14, ratio: ratio), + m21: morpher.tween(from: from.m21, to: to.m21, ratio: ratio), + m22: morpher.tween(from: from.m22, to: to.m22, ratio: ratio), + m23: morpher.tween(from: from.m23, to: to.m23, ratio: ratio), + m24: morpher.tween(from: from.m24, to: to.m24, ratio: ratio), + m31: morpher.tween(from: from.m31, to: to.m31, ratio: ratio), + m32: morpher.tween(from: from.m32, to: to.m32, ratio: ratio), + m33: morpher.tween(from: from.m33, to: to.m33, ratio: ratio), + m34: morpher.tween(from: from.m34, to: to.m34, ratio: ratio), + m41: morpher.tween(from: from.m41, to: to.m41, ratio: ratio), + m42: morpher.tween(from: from.m42, to: to.m42, ratio: ratio), + m43: morpher.tween(from: from.m43, to: to.m43, ratio: ratio), + m44: morpher.tween(from: from.m44, to: to.m44, ratio: ratio)) } /// Initial normalized value (usually 0.0 or self if Double convertible) diff --git a/Sources/morphable/Morphable+CGAffineTransform.swift b/Sources/morphable/Morphable+CGAffineTransform.swift index 4c1ffe1..edc82d2 100644 --- a/Sources/morphable/Morphable+CGAffineTransform.swift +++ b/Sources/morphable/Morphable+CGAffineTransform.swift @@ -12,15 +12,15 @@ extension CGAffineTransform: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CGAffineTransform, + public static func morph(from: CGAffineTransform, to: CGAffineTransform, ratio: Double) -> CGAffineTransform { - return CGAffineTransform(a: morpher.tween(from.a, to: to.a, ratio: ratio), - b: morpher.tween(from.b, to: to.b, ratio: ratio), - c: morpher.tween(from.c, to: to.c, ratio: ratio), - d: morpher.tween(from.d, to: to.d, ratio: ratio), - tx: morpher.tween(from.tx, to: to.tx, ratio: ratio), - ty: morpher.tween(from.ty, to: to.ty, ratio: ratio)) + return CGAffineTransform(a: morpher.tween(from: from.a, to: to.a, ratio: ratio), + b: morpher.tween(from: from.b, to: to.b, ratio: ratio), + c: morpher.tween(from: from.c, to: to.c, ratio: ratio), + d: morpher.tween(from: from.d, to: to.d, ratio: ratio), + tx: morpher.tween(from: from.tx, to: to.tx, ratio: ratio), + ty: morpher.tween(from: from.ty, to: to.ty, ratio: ratio)) } /// Initial normalized value (usually 0.0 or self if Double convertible) diff --git a/Sources/morphable/Morphable+CGFloat.swift b/Sources/morphable/Morphable+CGFloat.swift index 04865f5..25bcb25 100644 --- a/Sources/morphable/Morphable+CGFloat.swift +++ b/Sources/morphable/Morphable+CGFloat.swift @@ -12,7 +12,7 @@ extension CGFloat: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CGFloat, + public static func morph(from: CGFloat, to: CGFloat, ratio: Double) -> CGFloat { return CGFloat(ratio) diff --git a/Sources/morphable/Morphable+CGPoint.swift b/Sources/morphable/Morphable+CGPoint.swift index 5023459..50a3099 100644 --- a/Sources/morphable/Morphable+CGPoint.swift +++ b/Sources/morphable/Morphable+CGPoint.swift @@ -12,11 +12,11 @@ extension CGPoint: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CGPoint, + public static func morph(from: CGPoint, to: CGPoint, ratio: Double) -> CGPoint { - return CGPoint(x: morpher.tween(from.x, to: to.x, ratio: ratio), - y: morpher.tween(from.y, to: to.y, ratio: ratio)) + return CGPoint(x: morpher.tween(from: from.x, to: to.x, ratio: ratio), + y: morpher.tween(from: from.y, to: to.y, ratio: ratio)) } diff --git a/Sources/morphable/Morphable+CGRect.swift b/Sources/morphable/Morphable+CGRect.swift index efa8318..9965f6f 100644 --- a/Sources/morphable/Morphable+CGRect.swift +++ b/Sources/morphable/Morphable+CGRect.swift @@ -12,11 +12,11 @@ extension CGRect: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CGRect, + public static func morph(from: CGRect, to: CGRect, ratio: Double) -> CGRect { - return CGRect(origin: CGPoint.morph(from.origin, to: to.origin, ratio: ratio), - size: CGSize.morph(from.size, to: to.size, ratio: ratio)) + return CGRect(origin: CGPoint.morph(from: from.origin, to: to.origin, ratio: ratio), + size: CGSize.morph(from: from.size, to: to.size, ratio: ratio)) } /// Initial normalized value (usually 0.0 or self if Double convertible) diff --git a/Sources/morphable/Morphable+CGSize.swift b/Sources/morphable/Morphable+CGSize.swift index 10fc8a3..984dcd4 100644 --- a/Sources/morphable/Morphable+CGSize.swift +++ b/Sources/morphable/Morphable+CGSize.swift @@ -12,11 +12,11 @@ extension CGSize: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: CGSize, + public static func morph(from: CGSize, to: CGSize, ratio: Double) -> CGSize { - return CGSize(width: morpher.tween(from.width, to: to.width, ratio: ratio), - height: morpher.tween(from.height, to: to.height, ratio: ratio)) + return CGSize(width: morpher.tween(from: from.width, to: to.width, ratio: ratio), + height: morpher.tween(from: from.height, to: to.height, ratio: ratio)) } /// Initial normalized value (usually 0.0 or self if Double convertible) public var initialValue: Double { return 0 } diff --git a/Sources/morphable/Morphable+Double.swift b/Sources/morphable/Morphable+Double.swift index 97af4ab..8175131 100644 --- a/Sources/morphable/Morphable+Double.swift +++ b/Sources/morphable/Morphable+Double.swift @@ -10,7 +10,7 @@ extension Double: Morphable { Returns the value converted by ratio */ - public static func morph(_ from: Double, + public static func morph(from: Double, to: Double, ratio: Double) -> Double { return ratio diff --git a/Sources/morphable/Morphable.swift b/Sources/morphable/Morphable.swift index 65d3bab..6f6137b 100644 --- a/Sources/morphable/Morphable.swift +++ b/Sources/morphable/Morphable.swift @@ -11,7 +11,7 @@ public protocol Morphable { Returns the value converted by ratio */ - static func morph(_ from: Self, to: Self, ratio: Double) -> Self + static func morph(from: Self, to: Self, ratio: Double) -> Self /// Initial ratio value (usually 0.0 or self if Double convertible) var initialValue: Double { get } diff --git a/Sources/scheduler/Proxy.swift b/Sources/scheduler/Proxy.swift index 6328f48..c644179 100644 --- a/Sources/scheduler/Proxy.swift +++ b/Sources/scheduler/Proxy.swift @@ -20,8 +20,8 @@ extension Scheduler { return subscriber.keys } - func tick(_ timeStamp: TimeInterval) { - subscriber.tick(timeStamp) + func tick(time timeStamp: TimeInterval) { + subscriber.tick(time: timeStamp) } } diff --git a/Sources/scheduler/Scheduler.swift b/Sources/scheduler/Scheduler.swift index 85f3203..02204be 100644 --- a/Sources/scheduler/Scheduler.swift +++ b/Sources/scheduler/Scheduler.swift @@ -5,7 +5,7 @@ import QuartzCore Dispatches time events to subscribers */ -final public class Scheduler: Dispatcher { +final class Scheduler: Dispatcher { /// Shared singleton public static let shared = Scheduler() @@ -19,13 +19,13 @@ final public class Scheduler: Dispatcher { return link }() - fileprivate var subscribers = Set() + private var subscribers = Set() var timeStamp: TimeInterval { return displayLink.timestamp } - fileprivate func runIfNeeded() { + private func runIfNeeded() { displayLink.isPaused = subscribers.count == 0 } @@ -33,7 +33,7 @@ final public class Scheduler: Dispatcher { func subscribe(_ subscriber: Subscriber) { let subscription = Proxy(subscriber: subscriber) - solveOverwrite(subscriber) + solveOverwrite(with: subscriber) subscribers.insert(subscription) runIfNeeded() } @@ -48,26 +48,26 @@ final public class Scheduler: Dispatcher { runIfNeeded() } - @objc fileprivate func update(_ link: CADisplayLink) { + @objc private func update(_ link: CADisplayLink) { subscribers.forEach { proxy in - proxy.tick(link.timestamp) + proxy.tick(time: link.timestamp) } } //MARK: overwrite - fileprivate func solveOverwrite(_ subscriber: Subscriber) { + private func solveOverwrite(with subscriber: Subscriber) { if subscriber.keys.count > 0 { - pauseAll(subscribersWithKeys(subscriber.keys)) + pauseAll(subscribers: subscribers(keys: subscriber.keys)) } } - fileprivate func subscribersWithKeys(_ keys: Set) -> [Proxy] { + private func subscribers(keys: Set) -> [Proxy] { return subscribers.filter { $0.keys.intersection(keys).count > 0 } } - fileprivate func pauseAll(_ subscribers: [Proxy]) { + private func pauseAll(subscribers: [Proxy]) { subscribers.forEach { ($0.subscriber as? Tweenable)?.paused = true } } diff --git a/Sources/scheduler/Subscriber.swift b/Sources/scheduler/Subscriber.swift index 17ed957..078af0d 100644 --- a/Sources/scheduler/Subscriber.swift +++ b/Sources/scheduler/Subscriber.swift @@ -3,5 +3,5 @@ import Foundation protocol Subscriber: class { var keys: Set { get } - func tick(_ time: TimeInterval) + func tick(time: TimeInterval) } diff --git a/Sources/timeline/TimeLine.swift b/Sources/timeline/TimeLine.swift index 5cd3480..74e48cd 100644 --- a/Sources/timeline/TimeLine.swift +++ b/Sources/timeline/TimeLine.swift @@ -10,30 +10,30 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit public typealias UpdateClosure = () -> () - fileprivate struct Span { + private struct Span { var start: TimeInterval var end: TimeInterval - func contains(_ time: TimeInterval) -> Bool { + func contains(time: TimeInterval) -> Bool { return start <= time && time < end } } - fileprivate struct TweenContainer { + private struct TweenContainer { var tween: Tweenable var span: Span - func scaled(_ value: Double) -> TweenContainer { - tween.scale = value + func scaled(by: Double) -> TweenContainer { + tween.scale = by return TweenContainer(tween: tween, - span: Span(start: span.start * value, - end: span.end * value)) + span: Span(start: span.start * by, + end: span.end * by)) } } //MARK: properties - fileprivate var container = [TweenContainer]() + private var container = [TweenContainer]() var onUpdate: UpdateClosure? //MARK: initializers @@ -47,7 +47,7 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit */ public init(tweens: [Tweenable]) { super.init() - tweens.forEach { add($0) } + tweens.forEach { add(tween: $0) } moveToStart(); } @@ -76,25 +76,25 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit */ public init(dictionaryLiteral elements: (Tweenable, Double)...) { super.init() - elements.forEach { add($0.0, shift: $0.1) } + elements.forEach { add(tween: $0.0, shift: $0.1) } self.moveToStart(); } //MARK: lifecycle private func moveToStart() { - container.filter { return $0.span.contains(0) } + container.filter { return $0.span.contains(time: 0) } .forEach { ($0.tween as? Updatable)?.update() } } /// Current time offset (seconds) override public var head: TimeInterval { didSet { - update(head, prevHead: oldValue) + update(head: head, prevHead: oldValue) } } - private func update(_ head: TimeInterval, prevHead: TimeInterval) { + private func update(head: TimeInterval, prevHead: TimeInterval) { var deffered: [() -> ()] = [] container.forEach { data in @@ -102,24 +102,24 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit let span = data.span let distance = span.start.distance(to: head) let distanceTo = min(max(0, distance), tweenable.duration) - if !paused && pointPassed(head, prevDelta: prevHead, point: span.start) { + if !paused && pointPassed(delta: head, prevDelta: prevHead, point: span.start) { tweenable.onStart?() } if distanceTo == distance { deffered.append({ - tweenable.seek(distanceTo) + tweenable.seek(offset: distanceTo) }) } else { - tweenable.seek(distanceTo) + tweenable.seek(offset: distanceTo) } - if !paused && pointPassed(head, prevDelta: prevHead, point: span.end) { + if !paused && pointPassed(delta: head, prevDelta: prevHead, point: span.end) { tweenable.onComplete?(true) } } deffered.forEach { $0() } } - private func pointPassed(_ delta: TimeInterval, prevDelta: TimeInterval, point: TimeInterval) -> Bool { + private func pointPassed(delta: TimeInterval, prevDelta: TimeInterval, point: TimeInterval) -> Bool { return delta == point || (delta > point && prevDelta < point) } @@ -138,7 +138,7 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit - Parameter shift: Delta to previous Tweenable (in seconds); defaults to 0 */ - public func add(_ tween: Tweenable, shift: TimeInterval = 0.0) { + public func add(tween: Tweenable, shift: TimeInterval = 0.0) { let start = duration + shift let end = start + tween.duration let data = TweenContainer(tween: tween, @@ -154,8 +154,8 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit - Parameter tweens: Array of Tweenables */ - public func add(_ tweens: [Tweenable]) { - tweens.forEach { add($0) } + public func add(tweens: [Tweenable]) { + tweens.forEach { add(tween: $0) } } //MARK: time @@ -173,7 +173,7 @@ final public class TimeLine: AbstractTweenable, Tweenable, ExpressibleByArrayLit /// Scale. Defaults to 1.0 public var scale: Double = 1.0 { didSet { - container = container.map { $0.scaled(scale) } + container = container.map { $0.scaled(by: scale) } } } diff --git a/Sources/tween/Tween.swift b/Sources/tween/Tween.swift index 5d6c3c5..7ed1e13 100644 --- a/Sources/tween/Tween.swift +++ b/Sources/tween/Tween.swift @@ -19,10 +19,10 @@ final public class Tween: AbstractTweenable, Tweenable, Updatable public let ease: Ease.TimingFunction /// Duration (seconds) - fileprivate(set) public var time: TimeInterval + private(set) public var time: TimeInterval /// Time offset (seconds) - fileprivate(set) public var delay: TimeInterval + private(set) public var delay: TimeInterval //MARK: callbacks @@ -84,7 +84,7 @@ final public class Tween: AbstractTweenable, Tweenable, Updatable span, duration - delay) let morphedValue = T.morph( - from, + from: from, to: to, ratio: ratio) onUpdate(head != duration ? morphedValue : to) @@ -127,7 +127,7 @@ final public class Tween: AbstractTweenable, Tweenable, Updatable } } - fileprivate var span: Double { + private var span: Double { return to.finalValue - from.initialValue } diff --git a/Sources/tweenable/AbstractTweenable.swift b/Sources/tweenable/AbstractTweenable.swift index e63719e..154ce65 100644 --- a/Sources/tweenable/AbstractTweenable.swift +++ b/Sources/tweenable/AbstractTweenable.swift @@ -57,12 +57,12 @@ open class AbstractTweenable: Subscriber, Schedulable { - Parameter delta: Time offset (seconds) */ - final public func seek(_ delta: TimeInterval) { + final public func seek(offset delta: TimeInterval) { head = min(max(delta, 0), duration) } var scheduler: Dispatcher = Scheduler.shared - fileprivate var startTime: TimeInterval = 0 + private var startTime: TimeInterval = 0 /// Start the animation final public func start() { @@ -74,7 +74,7 @@ open class AbstractTweenable: Subscriber, Schedulable { paused = true } - final func tick(_ time: TimeInterval) { + final func tick(time: TimeInterval) { if startTime == 0 { startTime = time } diff --git a/Sources/tweenable/Tweenable.swift b/Sources/tweenable/Tweenable.swift index bb7abcf..d4c9eca 100644 --- a/Sources/tweenable/Tweenable.swift +++ b/Sources/tweenable/Tweenable.swift @@ -35,9 +35,9 @@ public protocol Tweenable: class { /** Move head to a specific time offset - - Parameter delta: Time offset (seconds) + - Parameter offset: Time offset (seconds) */ - func seek(_ delta: TimeInterval) + func seek(offset: TimeInterval) } diff --git a/TRXTests/mocks/MockSubscriber.swift b/TRXTests/mocks/MockSubscriber.swift index 0e37fcb..115e52f 100644 --- a/TRXTests/mocks/MockSubscriber.swift +++ b/TRXTests/mocks/MockSubscriber.swift @@ -10,7 +10,7 @@ class MockSubscriber: Subscriber { var keys: Set = [] - func tick(_ time: TimeInterval) { + func tick(time: TimeInterval) { callCount.add(#function) } diff --git a/TRXTests/mocks/MockTweenable.swift b/TRXTests/mocks/MockTweenable.swift index e6e2159..9cc84d7 100644 --- a/TRXTests/mocks/MockTweenable.swift +++ b/TRXTests/mocks/MockTweenable.swift @@ -42,7 +42,7 @@ class MockTweenable: MockSubscriber, Tweenable, Updatable { var onComplete: CompletionClosure? func start() {} func stop() {} - func seek(_ delta: TimeInterval) { - head = delta + func seek(offset: TimeInterval) { + head = offset } } diff --git a/TRXTests/specs/morphable/Morphable+CATransform3DSpec.swift b/TRXTests/specs/morphable/Morphable+CATransform3DSpec.swift index 664eafa..ac21b12 100644 --- a/TRXTests/specs/morphable/Morphable+CATransform3DSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CATransform3DSpec.swift @@ -28,7 +28,7 @@ class Morphable_CATransform3D: QuickSpec { context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -42,7 +42,7 @@ class Morphable_CATransform3D: QuickSpec { context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -56,7 +56,7 @@ class Morphable_CATransform3D: QuickSpec { context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { diff --git a/TRXTests/specs/morphable/Morphable+CGAffineTransformSpec.swift b/TRXTests/specs/morphable/Morphable+CGAffineTransformSpec.swift index 6c69012..b78be99 100644 --- a/TRXTests/specs/morphable/Morphable+CGAffineTransformSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CGAffineTransformSpec.swift @@ -28,7 +28,7 @@ class Morphable_CGAffineTransform: QuickSpec { context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -41,7 +41,7 @@ class Morphable_CGAffineTransform: QuickSpec { context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -54,7 +54,7 @@ class Morphable_CGAffineTransform: QuickSpec { context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { diff --git a/TRXTests/specs/morphable/Morphable+CGFloatSpec.swift b/TRXTests/specs/morphable/Morphable+CGFloatSpec.swift index 038dd44..7fe37e5 100644 --- a/TRXTests/specs/morphable/Morphable+CGFloatSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CGFloatSpec.swift @@ -26,7 +26,7 @@ class Morphable_CGFloat: QuickSpec { context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -38,7 +38,7 @@ class Morphable_CGFloat: QuickSpec { context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -50,7 +50,7 @@ class Morphable_CGFloat: QuickSpec { context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { diff --git a/TRXTests/specs/morphable/Morphable+CGPointSpec.swift b/TRXTests/specs/morphable/Morphable+CGPointSpec.swift index 819f7f3..2935c30 100644 --- a/TRXTests/specs/morphable/Morphable+CGPointSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CGPointSpec.swift @@ -26,7 +26,7 @@ class Morphable_CGPointSpec: QuickSpec { context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -38,7 +38,7 @@ class Morphable_CGPointSpec: QuickSpec { context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -50,7 +50,7 @@ class Morphable_CGPointSpec: QuickSpec { context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { @@ -62,4 +62,4 @@ class Morphable_CGPointSpec: QuickSpec { } } -} \ No newline at end of file +} diff --git a/TRXTests/specs/morphable/Morphable+CGRectSpec.swift b/TRXTests/specs/morphable/Morphable+CGRectSpec.swift index cfbdf45..beef8d8 100644 --- a/TRXTests/specs/morphable/Morphable+CGRectSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CGRectSpec.swift @@ -26,7 +26,7 @@ class Morphable_CGRectSpec: QuickSpec { context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -38,7 +38,7 @@ class Morphable_CGRectSpec: QuickSpec { context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -50,7 +50,7 @@ class Morphable_CGRectSpec: QuickSpec { context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { @@ -63,4 +63,4 @@ class Morphable_CGRectSpec: QuickSpec { } -} \ No newline at end of file +} diff --git a/TRXTests/specs/morphable/Morphable+CGSizeSpec.swift b/TRXTests/specs/morphable/Morphable+CGSizeSpec.swift index 2662e4d..4e510fa 100644 --- a/TRXTests/specs/morphable/Morphable+CGSizeSpec.swift +++ b/TRXTests/specs/morphable/Morphable+CGSizeSpec.swift @@ -26,7 +26,7 @@ class Morphable_CGSizeSpec: QuickSpec{ context("beginning") { beforeEach() { - subject.seek(0) + subject.seek(offset: 0) } it("should have correct value") { @@ -38,7 +38,7 @@ class Morphable_CGSizeSpec: QuickSpec{ context("end") { beforeEach() { - subject.seek(1) + subject.seek(offset: 1) } it("should have correct value") { @@ -50,7 +50,7 @@ class Morphable_CGSizeSpec: QuickSpec{ context("between") { beforeEach() { - subject.seek(0.5) + subject.seek(offset: 0.5) } it("should have correct value") { diff --git a/TRXTests/specs/shared/TweenableSharedExmaples.swift b/TRXTests/specs/shared/TweenableSharedExmaples.swift index 834f240..d3192c5 100644 --- a/TRXTests/specs/shared/TweenableSharedExmaples.swift +++ b/TRXTests/specs/shared/TweenableSharedExmaples.swift @@ -71,7 +71,7 @@ class TweenableExamples: QuickConfiguration { describe("seek") { it("adjusts head") { - subject.seek(expectedDuration * 0.5) + subject.seek(offset: expectedDuration * 0.5) expect(subject.head) == expectedDuration * 0.5 } @@ -104,8 +104,8 @@ class TweenableExamples: QuickConfiguration { context("seeking to beginning") { beforeEach() { - subject.seek(subject.duration / 2) - subject.seek(0) + subject.seek(offset: subject.duration / 2) + subject.seek(offset: 0) } it("shouldn't trigger callback") { @@ -117,8 +117,8 @@ class TweenableExamples: QuickConfiguration { context("seeking to end") { beforeEach() { - subject.seek(subject.duration / 2) - subject.seek(subject.duration) + subject.seek(offset: subject.duration / 2) + subject.seek(offset: subject.duration) } it("shouldn't trigger callback") { @@ -176,8 +176,8 @@ class TweenableExamples: QuickConfiguration { beforeEach() { subject.start() - subject.tick(1.0) - subject.tick(expectedDuration + 1.0) + subject.tick(time: 1.0) + subject.tick(time: expectedDuration + 1.0) } it("unsubscribes") { diff --git a/TRXTests/specs/timeline/TimeLineSpec.swift b/TRXTests/specs/timeline/TimeLineSpec.swift index 5e10521..50fb845 100644 --- a/TRXTests/specs/timeline/TimeLineSpec.swift +++ b/TRXTests/specs/timeline/TimeLineSpec.swift @@ -25,9 +25,9 @@ class TimeLineSpec: QuickSpec { let factory: TweenFactory.FactoryClosure = { let timeline = TimeLine() - timeline.add(tweenA, shift: 0.1) - timeline.add(tweenB, shift: 0.2) - timeline.add(tweenC, shift: -0.6) + timeline.add(tween: tweenA, shift: 0.1) + timeline.add(tween: tweenB, shift: 0.2) + timeline.add(tween: tweenC, shift: -0.6) return timeline } @@ -70,9 +70,9 @@ class TimeLineSpec: QuickSpec { describe("when single tweens added") { beforeEach() { - subject.add(tweenA) - subject.add(tweenB) - subject.add(tweenC) + subject.add(tween: tweenA) + subject.add(tween: tweenB) + subject.add(tween: tweenC) } it("should contain tweens") { @@ -84,7 +84,7 @@ class TimeLineSpec: QuickSpec { describe("when array of tweens added") { beforeEach() { - subject.add([tweenA, tweenB, tweenC]) + subject.add(tweens: [tweenA, tweenB, tweenC]) } it("should contain tweens") { @@ -103,33 +103,33 @@ class TimeLineSpec: QuickSpec { mockScheduler = MockScheduler() subject.scheduler = mockScheduler - subject.add([tweenA, tweenB]) + subject.add(tweens: [tweenA, tweenB]) subject.start() } it("calls start A") { - subject.tick(1) - subject.tick(1.1) + subject.tick(time: 1) + subject.tick(time: 1.1) expect(tweenA.onStartCalled) == 1 } it("calls completion A") { - subject.tick(1) - subject.tick(1.5) - subject.tick(2.1) + subject.tick(time: 1) + subject.tick(time: 1.5) + subject.tick(time: 2.1) expect(tweenA.onCompleteCalled) == 1 } it("calls Start B") { - subject.tick(1) - subject.tick(2.1) + subject.tick(time: 1) + subject.tick(time: 2.1) expect(tweenB.onStartCalled) == 1 } it("calls completion B") { - subject.tick(1) - subject.tick(2.1) - subject.tick(4.1) + subject.tick(time: 1) + subject.tick(time: 2.1) + subject.tick(time: 4.1) expect(tweenB.onCompleteCalled) == 1 } @@ -150,7 +150,7 @@ class TimeLineSpec: QuickSpec { context("on start") { beforeEach() { - subject.seek(0.1) + subject.seek(offset: 0.1) } it("sets head A with correct value") { @@ -170,7 +170,7 @@ class TimeLineSpec: QuickSpec { context("on B") { beforeEach() { - subject.seek(1.3) + subject.seek(offset: 1.3) } it("sets head A with correct value") { @@ -190,7 +190,7 @@ class TimeLineSpec: QuickSpec { context("on C") { beforeEach() { - subject.seek(3.3) + subject.seek(offset: 3.3) } it("sets head A with correct value") { @@ -211,7 +211,7 @@ class TimeLineSpec: QuickSpec { context("on end") { beforeEach() { - subject.seek(4.8) + subject.seek(offset: 4.8) } it("sets head A with correct value") { diff --git a/TRXTests/specs/tween/TweenSpec.swift b/TRXTests/specs/tween/TweenSpec.swift index 815c1bc..885e411 100644 --- a/TRXTests/specs/tween/TweenSpec.swift +++ b/TRXTests/specs/tween/TweenSpec.swift @@ -34,17 +34,17 @@ class TweenSpec: QuickSpec { describe("seek") { it("should return correct value on start") { - subject.seek(0) + subject.seek(offset: 0) expect(currentValue) == 1 } it("should return correct value in between") { - subject.seek(1) + subject.seek(offset: 1) expect(currentValue) == 2.5 } it("should return correct value on completion") { - subject.seek(2) + subject.seek(offset: 2) expect(currentValue) == 4.0 } @@ -71,22 +71,22 @@ class TweenSpec: QuickSpec { context("seek") { it("should return correct value on start") { - subject.seek(0) + subject.seek(offset: 0) expect(currentValue) == 1 } it("should return correct value after delay") { - subject.seek(0.5) + subject.seek(offset: 0.5) expect(currentValue) == 1 } it("should return correct value in between") { - subject.seek(1.5) + subject.seek(offset: 1.5) expect(currentValue) == 2.5 } it("should return correct value on complition") { - subject.seek(2.5) + subject.seek(offset: 2.5) expect(currentValue) == 4.0 } @@ -107,17 +107,17 @@ class TweenSpec: QuickSpec { context("seek") { it("should return correct value on start") { - subject.seek(0) + subject.seek(offset: 0) expect(currentValue) == 4 } it("should return correct value in between") { - subject.seek(1) + subject.seek(offset: 1) expect(currentValue) == 2.5 } it("should return correct value on completion") { - subject.seek(2) + subject.seek(offset: 2) expect(currentValue) == 1 } @@ -138,22 +138,22 @@ class TweenSpec: QuickSpec { context("seek") { it("should return correct value on start") { - subject.seek(0) + subject.seek(offset: 0) expect(currentValue) == 1 } it("should return correct value after delay") { - subject.seek(2) + subject.seek(offset: 2) expect(currentValue) == 1 } it("should return correct value in between") { - subject.seek(4) + subject.seek(offset: 4) expect(currentValue) == 2.5 } it("should return correct value on completion") { - subject.seek(6) + subject.seek(offset: 6) expect(currentValue) == 4.0 }