1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-21 09:59:10 +03:00

Merge pull request #324 from f3dm76/task/reverseShapeAnimation

Fix #323: Reverse shape animation doesn't work
This commit is contained in:
Yuri Strot 2018-04-24 00:32:54 +07:00 committed by GitHub
commit 1751d741e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,21 +9,18 @@
class ShapeAnimation: AnimationImpl<Shape> {
convenience init(animatedNode: Shape, finalValue: Shape, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {
let nodeId = animatedNode.id
let interpolationFunc = { (t: Double) -> Shape in
if t == 0 {
let initialNode = Node.nodeBy(id: nodeId) as! Shape
return Shape(form: initialNode.form,
fill: initialNode.fill,
stroke: initialNode.stroke,
place: initialNode.place,
opaque: initialNode.opaque,
opacity: initialNode.opacity,
clip: initialNode.clip,
effect: initialNode.effect,
visible: initialNode.visible,
tag: initialNode.tag)
return Shape(form: animatedNode.form,
fill: animatedNode.fill,
stroke: animatedNode.stroke,
place: animatedNode.place,
opaque: animatedNode.opaque,
opacity: animatedNode.opacity,
clip: animatedNode.clip,
effect: animatedNode.effect,
visible: animatedNode.visible,
tag: animatedNode.tag)
}
return finalValue
@ -56,6 +53,25 @@ class ShapeAnimation: AnimationImpl<Shape> {
override public func pause() {
stop()
}
open override func reverse() -> Animation {
let factory = { () -> (Double) -> Shape in
let original = self.timeFactory()
return { (t: Double) -> Shape in
return original(1.0 - t)
}
}
let node = Node.nodeBy(id: nodeId!)
let reversedAnimation = ShapeAnimation(animatedNode: node as! Shape,
factory: factory,
animationDuration: duration,
fps: logicalFps)
reversedAnimation.progress = progress
reversedAnimation.completion = completion
return reversedAnimation
}
}
public extension AnimatableVariable {