1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 13:15:35 +03:00

AnimatableVariable type constraints

This commit is contained in:
Viktor Sukochev 2016-09-21 15:47:58 +06:00
parent aadc0a8867
commit 2a9bb9a4f1
4 changed files with 16 additions and 6 deletions

View File

@ -1,7 +1,12 @@
import Foundation
extension Double: Interpolable {
public protocol DoubleInterpolation: Interpolable {
}
extension Double: DoubleInterpolation {
public func interpolate(endValue: Double, progress: Double) -> Double {
return self + (endValue - self) * progress
}
}

View File

@ -1,6 +1,10 @@
import Foundation
extension Transform: Interpolable {
public protocol TransformInterpolation: Interpolable {
}
extension Transform: TransformInterpolation {
public func interpolate(endValue: Transform, progress: Double) -> Transform {
return Transform(m11: self.m11.interpolate(endValue.m11, progress: progress),
m12: self.m12.interpolate(endValue.m12, progress: progress),

View File

@ -39,7 +39,8 @@ internal class OpacityAnimation: AnimationImpl<Double> {
public typealias OpacityAnimationDescription = AnimationDescription<Double>
public extension AnimatableVariable {
public extension AnimatableVariable where T: DoubleInterpolation {
// public func animate(desc: AnimationDescription<T: Double>) {
public func animate(desc: OpacityAnimationDescription) {
guard let node = self.node else {
return
@ -48,7 +49,7 @@ public extension AnimatableVariable {
let _ = OpacityAnimation(animatedNode: node, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}
public func animation(desc: OpacityAnimationDescription) -> Animation {
public func animation(desc: OpacityAnimationDescription) -> Animation {
guard let node = self.node else {
return EmptyAnimation(completion: { })
}
@ -72,4 +73,4 @@ public extension AnimatableVariable {
return OpacityAnimation(animatedNode: node, valueFunc: valueFrunc, animationDuration: during, delay: delay)
}
}
}

View File

@ -38,7 +38,7 @@ internal class TransformAnimation: AnimationImpl<Transform> {
public typealias TransformAnimationDescription = AnimationDescription<Transform>
public extension AnimatableVariable {
public extension AnimatableVariable where T: TransformInterpolation {
public func animate(desc: TransformAnimationDescription) {
guard let node = self.node else {
return