mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 13:15:35 +03:00
Simple animation delay implementation
This commit is contained in:
parent
e328232fa3
commit
8a851edbb2
@ -27,6 +27,7 @@ class BasicAnimation: Animation {
|
||||
var removeFunc: (() -> ())?
|
||||
var progress = 0.0
|
||||
var repeatCount = 0.0
|
||||
var delay = 0.0
|
||||
var autoreverses = false
|
||||
var onProgressUpdate: ((Double) -> ())?
|
||||
var easing = Easing.Ease
|
||||
@ -81,13 +82,15 @@ internal class AnimationImpl<T: Interpolable>: BasicAnimation {
|
||||
let duration: Double
|
||||
let logicalFps: UInt
|
||||
|
||||
init(observableValue: Variable<T>, valueFunc: (Double) -> T, animationDuration: Double, fps: UInt = 30) {
|
||||
value = observableValue
|
||||
duration = animationDuration
|
||||
vFunc = valueFunc
|
||||
logicalFps = fps
|
||||
init(observableValue: Variable<T>, valueFunc: (Double) -> T, animationDuration: Double, delay: Double = 0.0, fps: UInt = 30) {
|
||||
self.value = observableValue
|
||||
self.duration = animationDuration
|
||||
self.vFunc = valueFunc
|
||||
self.logicalFps = fps
|
||||
|
||||
super.init()
|
||||
|
||||
self.delay = delay
|
||||
}
|
||||
|
||||
convenience init(observableValue: Variable<T>, startValue: T, finalValue: T, animationDuration: Double) {
|
||||
@ -123,12 +126,14 @@ class EmptyAnimation: BasicAnimation {
|
||||
public class AnimationDescription <T> {
|
||||
public let valueFunc: (Double) -> T
|
||||
public var duration = 0.0
|
||||
public init(valueFunc: (Double) -> T, duration: Double = 1.0) {
|
||||
public var delay = 0.0
|
||||
public init(valueFunc: (Double) -> T, duration: Double = 1.0, delay: Double = 0.0) {
|
||||
self.valueFunc = valueFunc
|
||||
self.duration = duration
|
||||
self.delay = delay
|
||||
}
|
||||
|
||||
public func t(duration: Double) -> AnimationDescription<T> {
|
||||
return AnimationDescription(valueFunc: valueFunc, duration: duration)
|
||||
public func t(duration: Double, delay: Double = 0.0) -> AnimationDescription<T> {
|
||||
return AnimationDescription(valueFunc: valueFunc, duration: duration, delay: delay)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,14 @@
|
||||
let animationProducer = AnimationProducer()
|
||||
class AnimationProducer {
|
||||
|
||||
func addAnimation(animation: BasicAnimation) {
|
||||
func addAnimation(animation: BasicAnimation, withoutDelay: Bool = false) {
|
||||
|
||||
if animation.delay > 0.0 && !withoutDelay {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(animation.delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
|
||||
self.addAnimation(animation, withoutDelay: true)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if animation.type == .Empty {
|
||||
executeCompletion(animation)
|
||||
|
@ -3,17 +3,17 @@ import RxSwift
|
||||
|
||||
internal class OpacityAnimation: AnimationImpl<Double> {
|
||||
|
||||
convenience init(animatedNode: Node, startValue: Double, finalValue: Double, animationDuration: Double, autostart: Bool = false, fps: UInt = 30) {
|
||||
convenience init(animatedNode: Node, startValue: Double, finalValue: Double, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {
|
||||
|
||||
let interpolationFunc = { (t: Double) -> Double in
|
||||
return startValue.interpolate(finalValue, progress: t)
|
||||
}
|
||||
|
||||
self.init(animatedNode: animatedNode, valueFunc: interpolationFunc, animationDuration: animationDuration, autostart: autostart, fps: fps)
|
||||
self.init(animatedNode: animatedNode, valueFunc: interpolationFunc, animationDuration: animationDuration, delay: delay, autostart: autostart, fps: fps)
|
||||
}
|
||||
|
||||
init(animatedNode: Node, valueFunc: (Double) -> Double, animationDuration: Double, autostart: Bool = false, fps: UInt = 30) {
|
||||
super.init(observableValue: animatedNode.opacityVar, valueFunc: valueFunc, animationDuration: animationDuration, fps: fps)
|
||||
init(animatedNode: Node, valueFunc: (Double) -> Double, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {
|
||||
super.init(observableValue: animatedNode.opacityVar, valueFunc: valueFunc, animationDuration: animationDuration, delay: delay, fps: fps)
|
||||
type = .Opacity
|
||||
node = animatedNode
|
||||
|
||||
@ -56,20 +56,20 @@ public extension AnimatableVariable {
|
||||
return OpacityAnimation(animatedNode: node, valueFunc: desc.valueFunc, animationDuration: desc.duration, autostart: false)
|
||||
}
|
||||
|
||||
public func animate(from from: Double, to: Double, during: Double) {
|
||||
self.animate((from >> to).t(during))
|
||||
public func animate(from from: Double, to: Double, during: Double, delay: Double = 0.0) {
|
||||
self.animate((from >> to).t(during, delay: delay))
|
||||
}
|
||||
|
||||
public func animation(from from: Double, to: Double, during: Double) -> Animation {
|
||||
return self.animation((from >> to).t(during))
|
||||
public func animation(from from: Double, to: Double, during: Double, delay: Double = 0.0) -> Animation {
|
||||
return self.animation((from >> to).t(during, delay: delay))
|
||||
}
|
||||
|
||||
public func animation(valueFunc valueFrunc: (Double) -> Double, during: Double) -> Animation {
|
||||
public func animation(valueFunc valueFrunc: (Double) -> Double, during: Double, delay: Double = 0.0) -> Animation {
|
||||
guard let node = self.node else {
|
||||
return EmptyAnimation(completion: { })
|
||||
}
|
||||
|
||||
return OpacityAnimation(animatedNode: node, valueFunc: valueFrunc, animationDuration: during)
|
||||
return OpacityAnimation(animatedNode: node, valueFunc: valueFrunc, animationDuration: during, delay: delay)
|
||||
}
|
||||
|
||||
}
|
@ -2,17 +2,17 @@ import RxSwift
|
||||
|
||||
internal class TransformAnimation: AnimationImpl<Transform> {
|
||||
|
||||
convenience init(animatedNode: Node, startValue: Transform, finalValue: Transform, animationDuration: Double, autostart: Bool = false, fps: UInt = 30) {
|
||||
convenience init(animatedNode: Node, startValue: Transform, finalValue: Transform, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {
|
||||
|
||||
let interpolationFunc = { (t: Double) -> Transform in
|
||||
return startValue.interpolate(finalValue, progress: t)
|
||||
}
|
||||
|
||||
self.init(animatedNode: animatedNode, valueFunc: interpolationFunc, animationDuration: animationDuration, autostart: autostart, fps: fps)
|
||||
self.init(animatedNode: animatedNode, valueFunc: interpolationFunc, animationDuration: animationDuration, delay: delay, autostart: autostart, fps: fps)
|
||||
}
|
||||
|
||||
init(animatedNode: Node, valueFunc: (Double) -> Transform, animationDuration: Double, autostart: Bool = false, fps: UInt = 30) {
|
||||
super.init(observableValue: animatedNode.placeVar, valueFunc: valueFunc, animationDuration: animationDuration, fps: fps)
|
||||
init(animatedNode: Node, valueFunc: (Double) -> Transform, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {
|
||||
super.init(observableValue: animatedNode.placeVar, valueFunc: valueFunc, animationDuration: animationDuration, delay: delay, fps: fps)
|
||||
type = .AffineTransformation
|
||||
node = animatedNode
|
||||
|
||||
@ -55,20 +55,20 @@ public extension AnimatableVariable {
|
||||
return TransformAnimation(animatedNode: node, valueFunc: desc.valueFunc, animationDuration: desc.duration, autostart: false)
|
||||
}
|
||||
|
||||
public func animate(from from: Transform? = nil, to: Transform, during: Double) {
|
||||
self.animate(((from ?? node!.place) >> to).t(during))
|
||||
public func animate(from from: Transform? = nil, to: Transform, during: Double, delay: Double = 0.0) {
|
||||
self.animate(((from ?? node!.place) >> to).t(during, delay: delay))
|
||||
}
|
||||
|
||||
public func animation(from from: Transform, to: Transform, during: Double) -> Animation {
|
||||
return self.animation((from >> to).t(during))
|
||||
public func animation(from from: Transform, to: Transform, during: Double, delay: Double = 0.0) -> Animation {
|
||||
return self.animation((from >> to).t(during, delay: delay))
|
||||
}
|
||||
|
||||
public func animation(valueFunc valueFrunc: (Double) -> Transform, during: Double) -> Animation {
|
||||
public func animation(valueFunc valueFrunc: (Double) -> Transform, during: Double, delay: Double = 0.0) -> Animation {
|
||||
guard let node = self.node else {
|
||||
return EmptyAnimation(completion: { })
|
||||
}
|
||||
|
||||
return TransformAnimation(animatedNode: node, valueFunc: valueFrunc, animationDuration: during)
|
||||
return TransformAnimation(animatedNode: node, valueFunc: valueFrunc, animationDuration: during, delay: delay)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user